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日创建