title: How do I plot multiple data subset forecast predictions onto a single plot
body: <p>I am new to R and have found this site extremely helpful, so here is my first posted question.  I appreciate your assistance and acknowledge the wisdom on this site.</p>
  
  <p><strong>Background:</strong>  Start with 5 years of weekly sales data to develop a forecast for future production based on weekly sales with a very strong year seasonality.  Determined the starting point with:</p>
  
  <pre><code>auto.fit &lt;- auto.arima(arima.ts, stepwise=FALSE, parallel=TRUE, num.cores=6, trace=TRUE )
  &gt; ARIMA(2,1,2)(0,0,1)[52] with drift.  
  </code></pre>
  
  <p>Now I wish to certify the accuracy with visual plotting of multiple 'windows' into the data and compare to the actual values. (This included logging the AIC values.)  In other words, the function loops through the data at programmed intervals recomputing/plotting the forecast onto the same plot.  It plotted correctly when my window started at the head of the data.  Now I am looking at a moving 104 week window and the results are all overlaid starting at 104th observation.</p>
  
  <pre><code>require(forecast)   ##[EDITED for simplified clarity]
  
  data &lt;- rep(cos(1:52*(3.1416/26)),5)*100+1000+c(1:26,25:0)
  
  # Create the current fit on data and predict one year out
  plot(data, type="l", xlab="weeks", ylab="counts",main="Overlay forecasts &amp; actuals",
       sub="green=FIT(1-105,by 16) wks back &amp; PREDICT(26) wks, blue=52 wks")
  result &lt;- tryCatch({
    arima.fit &lt;- auto.arima(tail(data,156)) 
    arima.pred &lt;- predict(arima.fit, n.ahead=52)
    lines(arima.pred$pred, col="blue")
    lines(arima.pred$pred+2*arima.pred$se, col="red")
    lines(arima.pred$pred-2*arima.pred$se, col="red")
  }, error = function(e) {return(e$message)} )  ## Trap error
  
  # Loop and perform comparison plotting of forecast to actuals
  for (j in seq(1,105,by=16)) { 
    result &lt;- tryCatch({
      ############## This plotted correctly as "Arima(head(data,-j),..."
      arima1.fit &lt;- auto.arima(head(tail(data,-j),156))
      arima1.pred &lt;- predict(arima1.fit, n.ahead=52)
      lines(arima1.pred$pred, col="green", lty=(numtests %% 6) + 1 )
    }, error = function(e) {return(e$message)}) ## Trap errors
  }      
  </code></pre>
  
  <p>The plots were accurate when all the forecasting included the head of the file, however, the AIC was not comparable between forecast windows because the sample size kept shrinking.</p>
  
  <p><strong>Question:</strong> How do I show the complete 5 years of sales data and overlay forecasts at programmed intervals which are computed from a rolling window of 3 years (156 observations)?  </p>
  
  <p>The AIC values logged are comparable using the rolling window approach, but all the forecasts overlay starting at observation 157.  I tried making the data into a time series and found the initial data plotted correctly on a time axis, but the forecasts were not time series, so they did not display.  </p>