R barplot x轴长度和标签

时间:2014-09-12 20:19:05

标签: r

我想使用条形图来显示在时间单位(x轴)上相对于渐变(y轴)测量的位移。然而,绘图工作,我需要能够定义x轴的长度(从1:366开始==这是我在全df中所有测量的最小值和最大值) - 所以我生产的所有条形图具有相同的长度(起点和终点)。另外,我希望沿x轴每10个单位时间贴一个标签。我还没设法创造这样的。一个可重复的例子和我在下面的步骤:

daybeg<-as.numeric(c("291.37561", "75.62574" , "196.37539" ,  "69.62543" ,  "93.37560" , 
"107.62561" , "196.62595" , "211.62557" , "174.87560" , "326.87566",
"224.12542"  , "72.12561" , "246.62544" ,  "61.62574" , "358.37556" , 
"299.12561" , "109.12560"  , "83.87560" , "16.87560"  , "47.87542"))

xdisspeed<-as.numeric(c("135.7357914","24.8621089",
"-216.3525499","159.3480878","124.7417427","-44.1748472",
"-271.1816785","-14.1738848","-61.0028242","-4.1711081", "-149.8402704","22.5010417",
" 0.9998611","21.6817234","-38.4359401", "-1116.1317216","145.0873211","222.6752537",
" 5.2331234","0.9992136"))

df<-data.frame(daybeg,xdisspeed)

ord<-df[order(df$daybeg),]
bpdisplan <- barplot(ord$xdisspeed,axes=T,ylim=c(-1200,1200),  
   names.arg=round(ord$daybeg,0), 
   xlab="Days since 10 January.", axis.lty=1,tcl = 0.25, 
   ylab="Displacement (km)") 

1 个答案:

答案 0 :(得分:0)

据我所知,你所描述的内容与任何一种条形图的标准描述都不匹配。如果你只想绘制一堆笨拙的邮箱,那么

plot(xdisspeed~daybeg, ord, type="n", xaxt="n")
w<-3
with(ord, rect(daybeg-w/2, 0, daybeg+w/2,xdisspeed, col="#eeeeee"))
axis(1, at=seq(0, 355, by=10), cex.axis=.60)

enter image description here

请注意,R不会绘制默认重叠的轴标签,因此我减小了字体大小以使其每10个打印一次,但这取决于您的特定图形设备和输出大小,以确定实际工作的值。