如何使用plot完成预测线?

How to complete the forecast line using plot?

我一直在用 R 编写一个脚本来预测一个数字。

# Load Forecast library
library(forecast)

# Load dataset
bwi <- read.csv(file="C:/Users/nsoria/Downloads/AMS Globales/TEC_BWI.csv", header=TRUE, sep=';', dec=",")

# Create time series starting in January 2015
ts_bwi <- ts(bwi$BWI, frequency = 12, start = c(2015,1))

# Pull out the seasonal, trend, and irregular components from the time series 
model <- stl(ts_bwi, s.window = "periodic")

# Predict the next 5 months of SLA
pred <- forecast(model, h = 5)

# Plot the results
plot(pronostico)

这个输出给出了这个

不知何故,预测线与实际值没有关联。

问题:如何制作从最后一个已知值到第一个预测值的直线?

编辑 01/01:这里是 link 重现案例的 CSV 所在位置。

您需要像下面的代码一样将您的实时时间序列添加到预测序列中

pred_mod<-pred
ts_real<-pred$x
pred_mod$x<-ts(c(ts_real,pred$mean),frequency=12,start=c(2015,1))
plot(pred_mod)

here the result