R 绘图预测和实际值

R 绘图预测和实际值,r,time-series,forecasting,R,Time Series,Forecasting,我都喜欢。我需要统计专家的帮助。我对as中的几个值进行了简单的arima预测。但是我在列中取了一部分值作为 现在有一种方法可以在这里绘制实际值和预测值。2019年的实际值为4,8,12,16,预测值为9,10,11,12。我们能画出这个吗 as <- data.frame(a=c(1,2,3,4,2,4,6,8,4,8,12,16)) train_as <- as[c(1:8),] a1 <- ts(train_as,start = c(2017,1),end = c(2017

我都喜欢。我需要统计专家的帮助。我对
as
中的几个值进行了简单的arima预测。但是我在
列中取了一部分值作为

现在有一种方法可以在这里绘制实际值和预测值。2019年的实际值为4,8,12,16,预测值为9,10,11,12。我们能画出这个吗

as <- data.frame(a=c(1,2,3,4,2,4,6,8,4,8,12,16))
train_as <- as[c(1:8),]
a1 <- ts(train_as,start = c(2017,1),end = c(2017,8),frequency = 4)
fit_arima <-auto.arima(a1, trace= TRUE, ic ="aic")
print(summary(fit_arima))
checkresiduals(fit_arima)
fcst <- forecast(fit_arima,h=4)
autoplot(fcst,include = 8)

as您可以尝试以下方法,首先创建测试数据集:

test_as <- as[c(9:12),]
现在您可以绘制它:

library(ggplot2)
ggplot(df, aes(time, pred, group = 1)) +
  geom_line() +
  geom_line(aes(time, real, group = 1), color = "red")+
  geom_ribbon(aes(time, ymin = Lo95, ymax = Hi95), fill = "red", alpha = 0.25) +
  geom_ribbon(aes(time, ymin = Lo80, ymax = Hi80), fill = "red", alpha = 0.25) +
  theme_light()

使用带有
autolayer()
功能的forecast软件包很容易做到这一点

库(预测)
图书馆(GG2)
你能查一下吗?
library(ggplot2)
ggplot(df, aes(time, pred, group = 1)) +
  geom_line() +
  geom_line(aes(time, real, group = 1), color = "red")+
  geom_ribbon(aes(time, ymin = Lo95, ymax = Hi95), fill = "red", alpha = 0.25) +
  geom_ribbon(aes(time, ymin = Lo80, ymax = Hi80), fill = "red", alpha = 0.25) +
  theme_light()