?autoplot.forecast
If showgap=FALSE, the gap between the historical observations and the forecasts is removed.
However, for me it is not removed.
library(forecast)
d <- ts(rnorm(36), start = c(2021, 1), frequency = 12)
fc <- snaive(d, h = 12)
autoplot(fc, showgap = FALSE)
Using plot
works fine however
plot(fc, showgap = FALSE)
OP, I originally thought this was a bug in the
forecast::autoplot()
function, but it turns out it is not. The functionplot.forecast()
, which is run when you useplot()
on a'forecast'
object, contains theshowgap=
argument. The command?autoplot.forecast
does indicate theshowgap=
argument, but not forautoplot()
- it's for theplot.forecast()
function.The good news is that there appears to be a method within
autolayer(...)
that contains this argument and you can use it. i.e. check the help again forplot.forecast()
a bit lower and you'll see this:We can use
autolayer()
in concert withautoplot()
. So, this seems to work: