添加一个 geom_vline 到 autoplot 预测
Add a geom_vline to autoplot forecast
我想在预测中添加一条垂直线。假设我有以下内容
library(fpp2)
data(insurance)
autoplot(insurance)+
geom_vline(aes(xintercept = "2004-07")) #problem line
如何让 geom_vlinee()
与 autoplot()
相得益彰?
您的 xintercept
需要与绘图的 x 轴类型相同。在这种情况下,保险是一个时间序列,因此您可以通过
了解日期的存储方式
time(insurance)
Jan Feb Mar Apr May Jun Jul
2002 2002.000 2002.083 2002.167 2002.250 2002.333 2002.417 2002.500
2003 2003.000 2003.083 2003.167 2003.250 2003.333 2003.417 2003.500
2004 2004.000 2004.083 2004.167 2004.250 2004.333 2004.417 2004.500
2005 2005.000 2005.083 2005.167 2005.250
所以我们需要一年加上月份的分数
autoplot(insurance)+
geom_vline(xintercept = 2004 + (07 - 1) / 12)
我想在预测中添加一条垂直线。假设我有以下内容
library(fpp2)
data(insurance)
autoplot(insurance)+
geom_vline(aes(xintercept = "2004-07")) #problem line
如何让 geom_vlinee()
与 autoplot()
相得益彰?
您的 xintercept
需要与绘图的 x 轴类型相同。在这种情况下,保险是一个时间序列,因此您可以通过
time(insurance)
Jan Feb Mar Apr May Jun Jul
2002 2002.000 2002.083 2002.167 2002.250 2002.333 2002.417 2002.500
2003 2003.000 2003.083 2003.167 2003.250 2003.333 2003.417 2003.500
2004 2004.000 2004.083 2004.167 2004.250 2004.333 2004.417 2004.500
2005 2005.000 2005.083 2005.167 2005.250
所以我们需要一年加上月份的分数
autoplot(insurance)+
geom_vline(xintercept = 2004 + (07 - 1) / 12)