简体   繁体   English

R图中缺少x轴标签

[英]Missing x axis labels in R plot

I have three data frames, not very exciting data I know, but this is not the problem I am trying to address. 我有三个数据帧,我知道的数据并不十分令人兴奋,但这不是我要解决的问题。

  > Ascidcv
             Date   Average       SE
    3  2014-09-01 37.250000 6.326673
    15 2014-10-02  6.285714 2.738613
    > Ascidc1
              Date Average SE
    3   2014-10-15       0  0
    34  2014-11-12       0  0
    62  2014-12-11       0  0
    88  2015-02-11       0  0
    119 2015-03-09       0  0
    > Ascidc2
              Date Average SE
    18  2014-10-15       0  0
    48  2014-11-12       0  0
    75  2014-12-11       0  0
    103 2015-02-11       0  0
    135 2015-03-09       0  0

I use these data frames to produce a plot: 我使用这些数据框来生成图:

plot(Ascidcv$Date, Ascidcv$Average, type='p', pch=4, col="red", xlab='Date', ylab='', main=expression(italic('Ascidiella sp.')), xlim=c(as.Date("2014-09-01"), as.Date("2015-03-09")), ylim=c(0,120))
points(Ascidc1$Date, Ascidc1$Average, type='p', pch=19, xlab='Date', main=expression(italic('Ascidiella sp.')), xlim=c(as.Date("2014-09-01"),as.Date("2014-12-11")), ylim=c(0,100))
points(Ascidc2$Date, Ascidc2$Average, type='p', pch=2, col="blue", xlab='Date', ylab='Average num ind.', main=expression(italic('Bugula sp.')), xlim=c(as.Date("2014-09-01"),as.Date("2014-12-11")), ylim=c(0,100))
mtext("Average % cover",side=2,line=3)

For some reason only the months September, October and March are being plotted on the x axis, with November- February failing to appear. 由于某些原因,x轴上仅绘制了9月,10月和3月,而11月至2月则没有显示。 I am sure this is quite a simple fix but I can't seem to figure it out. 我确信这是一个非常简单的修复程序,但我似乎无法弄清楚。 Any assistance would be greatly appreciated! 任何帮助将不胜感激! Thanks! 谢谢!

You can do your plot in two steps: 您可以分两步进行绘图:

first, your plot without axis 首先,您的无轴图

plot(Ascidcv$Date, Ascidcv$Average, type='p', pch=4, col="red", xlab='Date',
     ylab='', main=expression(italic('Ascidiella sp.')), xlim=c(as.Date("2014-09-01"), 
     as.Date("2015-03-09")), ylim=c(0,120),xaxt="n")

then, add the axis with ticks at the first day of each month from September 2014 to march 2015 with axis.Date and a vector for the respective dates 然后,用蜱在每月的第一天从2014年9月添加的轴2015年3月与axis.Date和矢量用于各个日期

axis.Date(1, at=as.Date(c(paste0("2014-",c("09",10:12),"-01"),
          paste0("2015-0",1:3,"-01"))))

finally, add the other points and text 最后,添加其他要点和文字

points(Ascidc1$Date, Ascidc1$Average, type='p', pch=19, xlab='Date', 
       main=expression(italic('Ascidiella sp.')), xlim=c(as.Date("2014-09-01"),
       as.Date("2014-12-11")), ylim=c(0,100))

points(Ascidc2$Date, Ascidc2$Average, type='p', pch=2, col="blue", xlab='Date', 
       ylab='Average num ind.', main=expression(italic('Bugula sp.')), 
       xlim=c(as.Date("2014-09-01"),as.Date("2014-12-11")), ylim=c(0,100))

mtext("Average % cover",side=2,line=3)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM