R散点图中的轴位置
我试图在R中创建一个简单的散点图,其中x轴范围为-10:10,并将y轴重新定位到x=0点。这似乎是一个相当基本的操作,但我发现没有办法做到这一点。。。 谢谢你的帮助 创建一些数据R散点图中的轴位置,r,plot,position,scatter,R,Plot,Position,Scatter,我试图在R中创建一个简单的散点图,其中x轴范围为-10:10,并将y轴重新定位到x=0点。这似乎是一个相当基本的操作,但我发现没有办法做到这一点。。。 谢谢你的帮助 创建一些数据 x <- runif(50, -10, 10) y <- runif(50, -10, 10) 获得类似结果的另一种方法是使用ggplot2软件包: library(ggplot2) qplot(x, y) + geom_vline(xintercept=0) + geom_hline(yinterce
x <- runif(50, -10, 10)
y <- runif(50, -10, 10)
获得类似结果的另一种方法是使用ggplot2
软件包:
library(ggplot2)
qplot(x, y) + geom_vline(xintercept=0) + geom_hline(yintercept=0)
x参数定义x轴范围是绘图(…,xlim=c(-10,10))
。有关更多信息,请参见?par
。为什么要这样做,并在数据上绘制轴及其标签?这就是我讨厌Excel绘图的原因之一——这只是一件愚蠢的事情。数据后面的网格会更好。+1用于回答书面问题。我可能会建议las=1
(也可能bty=“n”
)abline(h=0,v=0)
是一种速记。甚至一条直线:绘图(x,y,panel.last=abline(h=0,v=0))
。
library(ggplot2)
qplot(x, y) + geom_vline(xintercept=0) + geom_hline(yintercept=0)
x <- runif(50, -10, 10)
y <- runif(50, -10, 10)
plot(x, y, yaxt="n") # don't plot y-axis, see ?par, section xaxt
axis(2, pos=0) # Draw y-axis at 0 line