Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在时间序列图上改变轴_R_Ggplot2_Forecast - Fatal编程技术网

R 在时间序列图上改变轴

R 在时间序列图上改变轴,r,ggplot2,forecast,R,Ggplot2,Forecast,我已经从下面的数据帧制作了一个时间序列 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

我已经从下面的数据帧制作了一个时间序列

     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轴?

转换为zoo并使用
缩放\u x\u yearmon

library(zoo)

z.Monthly.Demand <- as.zoo(ts.Monthly.Demand)
autoplot(z.Monthly.Demand) + scale_x_yearmon() + xlab("")

转换为动物园并使用
scale\u x\u yearmon

library(zoo)

z.Monthly.Demand <- as.zoo(ts.Monthly.Demand)
autoplot(z.Monthly.Demand) + scale_x_yearmon() + xlab("")

由于
autoplot
返回一个
ggplot
对象,您可以像在任何其他ggplot工作流中一样向其添加其他
ggplot
功能。这包括设置比例,例如使用
scale\u x\u date
并根据您的喜好提供日期间隔。
日期标签的两个格式选项

库(tidyverse)
图书馆(GGF)
ts1%
选择(需求)%>%
ts(开始=2010,频率=12)
自动绘图(ts1)+比例x日期(日期标签=“%m-%Y”)

autoplot(ts1)+缩放x\u日期(日期标签=“%B%Y”)

autoplot(ts1)+缩放x\u日期(日期标签=“%b'%y”)


由(v0.2.0)于2018-06-13创建。

由于
autoplot
返回
ggplot
对象,您可以像在任何其他ggplot工作流中一样向其添加其他
ggplot
功能。这包括设置比例,例如使用
scale\u x\u date
并根据您的喜好提供日期间隔。
日期标签的两个格式选项

库(tidyverse)
图书馆(GGF)
ts1%
选择(需求)%>%
ts(开始=2010,频率=12)
自动绘图(ts1)+比例x日期(日期标签=“%m-%Y”)

autoplot(ts1)+缩放x\u日期(日期标签=“%B%Y”)

autoplot(ts1)+缩放x\u日期(日期标签=“%b'%y”)

由(v0.2.0)于2018年6月13日创建