如果我们需要相应的列名,请遍历列的序列
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]]
或与
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))
}