仅在R中将x轴值更改为整数

时间:2017-08-07 20:58:48

标签: r plot

我正在绘制时间序列的水文数据。 y轴是水位,x是时间,仅显示主要刻度(年)。情节完美无缺,除了我在x轴标签上每年年底得到一个额外的“x.0”。数据中的所有年份值都是整数。

我已尝试舍入我的轴限制(xlim = c(round(2013,0)))但这没有多大帮助。

我不确定如何为一个示例生成可重现的数据,但这个数据子集最终会出现相同的问题: enter image description here

hyd<-^^THOSE DATA^^

hyd<-hyd[order(hyd$year),]

hyd2<-ts(hyd, frequency=12, start=c(2013,1))
hyd3<-hyd2[,3]
plot(hyd3, type="l",pch=20, xlab="",ylab="Mean water level (cm)",
     xlim=c(round(2013,0),round(2015,0)),ylim=c(-75,45), #Note the failed attempt at rounding
     col="black",lwd=2)

以下是此代码生成的图: enter image description here

我希望x轴为:2013 2014 2015.感谢任何帮助。对不起,令人困惑的数据格式。

更新:使用RuiBarrada的回复我得到了我需要的东西。工作代码:

plot(hydro4, type="l",pch=20, xlab="Year",ylab="Mean water level (cm)",
   xlim=c(2013,2016),ylim=c(-75,45),col="black",lwd=2,xaxt="n")
axis(1,at=2013:2015,labels=2013:2015)

0 个答案:

没有答案