R:镜像 y 轴的绘图
我有这个问题。我有一个热图(但我想这适用于每个图),但我需要镜像我的 y 轴。
我这里有一些示例代码:
library(gstat)
x <- seq(1,50,length=50)
y <- seq(1,50,length=50)
z <- rnorm(1000)
df <- data.frame(x=x,y=y,z=z)
image(df,col=heat.colors(256))
这将生成以下热图 但我需要镜像 y 轴。从顶部 0 开始,底部 50 开始。有人知道我必须做什么才能改变这一点吗?
I have this problem. I got a heatmap, (but i suppose this applies to every plot) but I need to mirror my y-axis.
I got here some example code:
library(gstat)
x <- seq(1,50,length=50)
y <- seq(1,50,length=50)
z <- rnorm(1000)
df <- data.frame(x=x,y=y,z=z)
image(df,col=heat.colors(256))
This will generate the following heatmap
But I need the y-axis mirrored. Starting with 0 on the top and 50 on the bottom. Does anybody has a clue as to what I must do to change this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请参阅 ?plot.default 的帮助页面,其中指定
所以
See the help page for ?plot.default, which specifies
So
这对你有用吗(不过,这有点黑客行为)?
Does this work for you (it's a bit of a hack, though)?
plotrix 包中的 revaxis 函数“反转 'x' 和 'y' 轴中的一个或两个轴的方向”。它不能解决您的问题(尼克的解决方案是正确的),但当您需要绘制具有反转轴的散点图时,它可能很有用。
The revaxis function in the plotrix package "reverses the sense of either or both the ‘x’ and ‘y’ axes". It doesn't solve your problem (Nick's solution is the correct one) but can be useful when you need to plot a scatterplot with reversed axes.
我会像这样使用
rev
:如果您不知道,请注意
df
实际上是一个函数。覆盖时您可能要小心。如果您rm(df)
,一切都会恢复正常。不要忘记按照尼克的建议重新标记 y 轴。
I would use
rev
like so:In case you were not aware, notice that
df
is actually a function. You might want to be careful when overwriting. If yourm(df)
, things will go back to normal.Don't forget to relabel the y axis as Nick suggests.
对于垂直轴向下增加的情况,我为以下问题提供了两种方法(两个不同的答案):
R - 像素矩阵的图像?
For the vertical axis increasing in the downward direction, I provided two ways (two different answers) for the following question:
R - image of a pixel matrix?