Hello,
I am trying to show all of my series which is 7 daily observations on a plot.
I formed a training set and a test set
My training set is composed of the 1st 5 observations and my test set of the last 2
I want to use autoplot and autolayer to show my series for the 7 observations and my forecasts
for the last two observations using different methods
# Libraries ###
library(forecast)
library(ggplot2)
Data
n = c(717,17385, 15201,14954, 13241, 13165, 246)
ts_rep <- ts(n, frequency = 1, start = as.Date("2019-11-17"))
# Autoplot ##
a_rep <- autoplot(ts_rep) +
ggtitle("Manual Changes by Day") +
xlab("Day") +
ylab("Thousands")
a_rep
Splitting data into training set and test set
Using the subset function I want to show all the series using autoplot
And the forecasts for the last 2 observations
I am getting the following error :
Error in forecast2plotdf(object, PI = PI, showgap = showgap) :
Could not find forecast x axis
mean_method <- meanf(ts_rep[1:5],h=2)
naive_method <- rwf(ts_rep[1:5],h=2)
seasonal_naive_method <- snaive(ts_rep[1:5],h=2)
autoplot(ts_rep) +
autolayer(mean_method, series="Mean", PI=FALSE) +
autolayer(naive_method, series="Naïve", PI=FALSE) +
autolayer(seasonal_naive_method, series="Seasonal naïve", PI=FALSE) +
xlab("Day") + ylab("Thousands") +
ggtitle("Forecasts for Daily Manual Changes") +
guides(colour=guide_legend(title="Forecast"))
I appreciate any help