View source: R/plot_predictions.R
plot_predictions | R Documentation |
Create a ggplot
object with a time series and, optionally, some future
values of the time series and several forecast for those future values.
plot_predictions(ts, future = NULL, predictions = NULL, sdp = TRUE)
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 |
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.
The ggplot
object representing the time series and its forecast.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.