控制时间序列图的x轴标签格式 - R.

时间:2016-09-09 13:20:29

标签: r plot timestamp time-series

是否有办法强制R在图表上打印时间戳为%m /%d /%Y?当我有短暂(<7天)的数据时,它会打印成一周中的几天,如下所示?

plot(station_171$datetime, station_171$stageheight, pch=ifelse(station_171$outcode ==122,24,21), col="black", bg=ifelse(station_171$outcode ==122,"red","NA")
     , xlab = "",xlim = c(min(station_101_7$datetime),max(station_101_7$datetime)), ylab = "")
legend("topright","171", bty = "n", cex=2)

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用axis.POSIXct格式化轴,如下所示:

axis.POSIXct(1,station_171$datetime, format = '%Y-%m-%d %H:%S')

还应确保在绘图函数中包含xaxt='n'以避免双重打印x轴标签。