[英]How to iteratively plot auto.arima forecasts using ggplot
I have the following data: 我有以下数据:
df
repo revrepo bankrate CRR Callrate
1 9.00 6.75 7.0 8.00 7.49
2 8.75 6.50 7.0 7.50 8.03
3 8.50 6.50 7.0 7.50 7.24
4 8.50 6.50 7.0 7.50 7.19
5 8.50 6.50 7.0 7.50 6.94
6 8.50 6.50 7.0 7.50 7.30
7 8.50 6.50 6.5 7.50 7.40
8 8.50 6.50 6.5 5.75 6.97
9 8.50 6.50 6.5 5.50 7.08
10 8.50 6.50 6.5 5.50 6.63
11 8.50 6.50 6.5 5.50 6.73
12 8.00 6.00 6.5 5.50 6.97
13 8.00 6.00 6.5 5.50 6.58
14 8.00 6.00 6.5 5.50 6.90
15 8.00 5.75 6.5 5.00 6.04
I am iteratively plotting the ts as below: 我正在反复绘制ts,如下所示:
y=df
colnames <- dimnames(y)[[2]]
(plots<-lapply(df,function(x) autoplot(fit<-forecast(auto.arima(ts(x,start=c(2001,4),end = c(2002,6),frequency = 12))))+labs(x = 'Time', y = paste(colnames[i])) + ggtitle(paste(colnames[i],'over Time'))+ theme(plot.title = element_text(hjust = 0.5)) +
yaztheme::theme_yaz() ))
I am not getting the correct title of the plots.Showing one of plots for reference: 我没有得到正确的地块名称。显示其中一个地块供参考:
Is there a better method to do the iterative timeseries forecasting and plotting of the forecasts. 是否有更好的方法来进行时间序列的迭代预测和预测的绘制。
If we need the corresponding column names, loop through the sequence of columns 如果我们需要相应的列名,请遍历各列的顺序
lst <- lapply(seq_along(df),function(i) {
autoplot(fit<-forecast(auto.arima(ts(df[[i]],start=c(2001,4),
end = c(2002,6),frequency = 12))))+
labs(x = 'Time', y = paste(colnames[i])) +
ggtitle(paste(colnames[i],'over Time'))+
theme(plot.title = element_text(hjust = 0.5))
}
)
lst[[5]]
Or the same with a for
loop 或与for
循环相同
lst <- vector('list', length(df))
for(i in seq_along(df)) {
lst[[i]] <- autoplot(forecast(auto.arima(ts(df[[i]],
start=c(2001,4),end = c(2002,6),frequency = 12))))+
labs(x = 'Time', y = paste(colnames[i])) +
gtitle(paste(colnames[i],'over Time'))+
theme(plot.title = element_text(hjust = 0.5))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.