在 timePlot() 函数中的 x 轴标签中显示年份
Show year in x axis labels in timePlot() function
我发现了一个相关问题 here,但我的故事是不同的。使用 R OpenAir 包,我正在尝试创建一些漂亮的时间序列图(时间段:2014 年 12 月 - 2015 年 5 月)。这是代码:
timePlot(data, pollutant=c("NO_predicted", "NO_modelled"), group = TRUE, cols=c("blue", "red"),
data.thresh = 0, xlab="Year", ylab="Observed and Predicted NO",
lty=c(1, 1), lwd=c(1, 1), xlim = as.POSIXct(c("2014-12-01", "2015-05-31")))
剧情是这样的:
我想通过在 x 轴标签中添加年份来让它更漂亮。例如Dec-14
、Jan-15
、Feb-15
等。
有人可以建议怎么做吗?
请阅读 timePlot
的文档。您感兴趣的有两个选项:
date.breaks Number of major x-axis intervals to use. The function will try and choose a sensible number of dates/times as well as
formatting the date/time appropriately to the range being considered.
This does not always work as desired automatically. The user can
therefore increase or decrease the number of intervals by adjusting
the value of date.breaks up or down.
date.format This option controls the date format on the x-axis. While timePlot generally sets the date format sensibly there can be
some situations where the user wishes to have more control. For format
types see strptime. For example, to format the date like “Jan-2012”
set date.format = "%b-%Y".
我发现了一个相关问题 here,但我的故事是不同的。使用 R OpenAir 包,我正在尝试创建一些漂亮的时间序列图(时间段:2014 年 12 月 - 2015 年 5 月)。这是代码:
timePlot(data, pollutant=c("NO_predicted", "NO_modelled"), group = TRUE, cols=c("blue", "red"),
data.thresh = 0, xlab="Year", ylab="Observed and Predicted NO",
lty=c(1, 1), lwd=c(1, 1), xlim = as.POSIXct(c("2014-12-01", "2015-05-31")))
剧情是这样的:
我想通过在 x 轴标签中添加年份来让它更漂亮。例如Dec-14
、Jan-15
、Feb-15
等。
有人可以建议怎么做吗?
请阅读 timePlot
的文档。您感兴趣的有两个选项:
date.breaks Number of major x-axis intervals to use. The function will try and choose a sensible number of dates/times as well as formatting the date/time appropriately to the range being considered. This does not always work as desired automatically. The user can therefore increase or decrease the number of intervals by adjusting the value of date.breaks up or down.
date.format This option controls the date format on the x-axis. While timePlot generally sets the date format sensibly there can be some situations where the user wishes to have more control. For format types see strptime. For example, to format the date like “Jan-2012” set date.format = "%b-%Y".