R plot:如何使用plot绘制水平线的直方图()
问题描述:
如何使用plot
将这个绘图横向调整,使得直方图条是水平的?R plot:如何使用plot绘制水平线的直方图()
size<- abs(rnorm(20,10,10))
age<-c(seq(1, 20, by=2))
plot(size~age, type=("n")); lines(size~age, type=c("l"), lines(size~age, type=c("h")))
我要的是大致这样的事情,与直方图线的水平:
我与
plot(size~age, type=("n"), yaxt="n", xaxt="n", ylab=""); lines(size~age, type=c("l"), lines(size~age, type=c("h"))); axis(4); axis(1,las=2)
,然后旋转做在其他软件中输出图像。
我想知道我怎么可以使用plot
函数来获取输出情节横盘,所以我可以让他们的小组在R
不必的R
外旋转它们。
UPDATE感谢来自@csgillespie非常有帮助的建议,我已经得到了这一点,这也让我对我的方式:
size<- abs(rnorm(20,10,10))
age<-c(seq(1, 40, by=2)) # sorry for the typo in the first set of example data above
plot(-age~size, type="n",yaxt="n", ylab="Age", xlab="Size")
lines(-age~size)
segments(0, -age, size, -age)
axis(2, labels=c(seq(0,max(age), by=5)), at=-c(seq(0,max(age), by=5)), las=1) # this is a more general approach to labelling the axis ticks
,这里是导致情节(不漂亮,但我想我从这里可以做其他):
答
你可以得到你想要的东西通过-age
然后手动添加的规模。
plot(-age~size, type="n",yaxt="n", xlab="", ylab="Age")
lines(-age~size)
segments(0, -age, size, -age)
axis(2, labels=c(0,5,10,15,20), at=-c(0,5,10,15,20), las=1)
上面的代码产生了一个与您示例图相同的图,除了y轴标签已被旋转。如果你想y轴标签旋转,然后在绘图命令使用ylab=""
与text
+0
非常感谢!我不知道这是一个简单的改变功能的标志。我之前也没有遇到'segments',所以这非常有帮助。我采用了更为通用的方法来标记刻度标记(请参阅我的更新),这对我的真实数据更有效。再次感谢 – Ben 2012-01-05 18:46:30
手动添加它进一步说明您可能会发现在这里:http://*.com/questions/ 3792803/is-it-it-to-rotate-a-plot-in-r-base-graphics – Seb 2012-01-05 10:26:02