Search code examples
rplottime-seriesarimaforecast

R: How to plot multiple ARIMA forecasts on the same time-series


I would like to plot several forecasts on the same plot in different colours, however, the scale is off. I'm open to any other methods.

reproducible example:

require(forecast)     

# MAKING DATA
data <- c(3.86000,  19.55810,  19.51091,  20.74048,  20.71333,  29.04191,  30.28864, 25.64300,  23.33368,  23.70870 , 26.16600  ,27.61286 , 27.88409 , 28.41400 , 24.81957 , 24.60952,  27.49857,  32.08000 , 29.98000, 27.49000 , 237.26150, 266.35478, 338.30000, 377.69476, 528.65905, 780.00000  )
a.ts <- ts(data,start=c(2005,1),frequency=12)

# FORECASTS
arima011_css =stats::arima(x = a.ts, order = c(0, 1, 1), method = "CSS") # css estimate
arima011_forecast = forecast(arima011_css, h=10, level=c(99.5))

arima321_css =stats::arima(x = a.ts, order = c(3, 2, 1), method = "CSS") # css estimate
arima321_forecast = forecast(arima321_css, h=10, level=c(99.5))

# MY ATTEMPT AT PLOTS
plot(arima321_forecast)
par(new=T)
plot(arima011_forecast)

enter image description here


Solution

  • Here is something similar to @jay.sf but using ggplot2.

    library(ggplot2)
    
    autoplot(a.ts) +
      autolayer(arima011_forecast, series = "ARIMA(0,1,1)", alpha = 0.5) +
      autolayer(arima321_forecast, series = "ARIMA(3,2,1)", alpha = 0.5) +
      guides(colour = guide_legend("Model"))
    

    Created on 2020-05-19 by the reprex package (v0.3.0)