I'm trying to plot forecast and real data on the same plot. But there is always gap between them on the image :

enter image description here

I use for the forecasting following code: y=boardings[,1] ## Simple Exponential smoothing #predict existing values results=HoltWinters(y,beta=FALSE, gamma=FALSE) #print data print(cbind(y,results$fitted)) #draw the plot with fitted values plot(results) #predict future values results2=forecast.HoltWinters(results,h=12) print(results2)

#draw the plot with prediction
plot.forecast(results2,lwd=1,xlab='time',ylab='log.boardings',main='12-month prediction by Exponential Smoothing')

The data is taken from the timeSeries package with name boardings.

I would really appreciate any help.


The data are in discrete months. The historical data are connected with a line, and the forecasts are connected with a line. So there is no gap, it is just that no line is drawn between the last historical observation and the first forecast.

  • $\begingroup$ Actually there is value for this period (March), but it does not plot it. Seems like it misses only March, the last value in the real data. $\endgroup$ – Ivan T Dec 9 '12 at 23:11
  • 1
    $\begingroup$ Three values are plotted in 2006, so it looks like March is being plotted to me. But unless you give replicable code, nobody can help further. The timeSeries package does not contain an object called boardings. I think you probably mean the TSA package. When I plot the boardings object from TSA, it is identical to what is plotted in your graph including the March 2006 figure. $\endgroup$ – Rob Hyndman Dec 10 '12 at 1:00
  • $\begingroup$ @Rob Hyndman : Is there any any possibility of joining the end of historical data and start of forecasted data with some dotted lines? $\endgroup$ – Ashish Anand Sep 11 '15 at 6:09
  • $\begingroup$ @Ashish. With R you can do whatever you like. $\endgroup$ – Rob Hyndman Sep 13 '15 at 7:59
  • 1
    $\begingroup$ @RobHyndman : Thanks achieved it with segments() in plot and geom_segment() in ggplot. $\endgroup$ – Ashish Anand Sep 15 '15 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.