我从以下数据帧制作了一个时间序列。
Year Month Demand
1 2010 January 48.5
2 2010 February 46.0
3 2010 March 54.4
4 2010 April 49.8
5 2010 May 48.1
6 2010 June 55.0
我使用以下内容来制作 ts 对象:
ts.Monthly.Demand=Monthly.Demand%>%
select(Demand)%>%
ts(start=2010,frequency=12)
我使用以下内容来制作情节:
ts.Monthly.Demand%>%
autoplot()
如何将月份添加到 x 轴?
由于autoplot
返回一个ggplot
对象,您可以ggplot
像在任何其他 ggplot 工作流程中一样向其添加其他函数。这包括设置比例,例如根据scale_x_date
您的喜好设置日期休息时间。几个格式化选项date_labels
:
library(tidyverse)
library(ggfortify)
ts1 <- df %>%
select(Demand) %>%
ts(start = 2010, frequency = 12)
autoplot(ts1) + scale_x_date(date_labels = "%m-%Y")
autoplot(ts1) + scale_x_date(date_labels = "%B %Y")
autoplot(ts1) + scale_x_date(date_labels = "%b '%y")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句