plot_predictions {vctsfr} | R Documentation |
Creates a ggplot object with a time series and some forecasts
Description
Create a ggplot
object with a time series and, optionally, some future
values of the time series and several forecast for those future values.
Usage
plot_predictions(ts, future = NULL, predictions = NULL, sdp = TRUE)
Arguments
ts |
a time series of class |
future |
NULL (default) or a time series of class |
predictions |
NULL (default) or a named list containing the predictions
for the future values. Each component of the list should contain a vector or
an object of class |
sdp |
logical. Should data points be shown? (default value |
Details
If future
or the forecasts in the prediction
list are vectors
then they are supposed to start after the last data of the time series.
Value
The ggplot
object representing the time series and its forecast.
Examples
# plot a time series, its future values and two forecasts
ts <- window(USAccDeaths, end = c(1977, 12))
f <- window(USAccDeaths, start = c(1978, 1))
prediction1 <- rep(mean(ts), 12)
prediction2 <- as.vector(window(ts, start = c(1977, 1)))
p <- list(Mean = prediction1, Naive = prediction2)
plot_predictions(ts, future = f, predictions = p)