Learn R Programming

tsfknn (version 0.5.0)

autoplot.knnForecast: Create a ggplot object from a knnForecast object

Description

It uses a knnForecast object to create a ggplot object that plots a time series and its forecast using KNN regression.

Usage

# S3 method for knnForecast
autoplot(forecast, highlight = "none", faceting = TRUE)

Value

The ggplot object representing a plotting with the forecast.

Arguments

forecast

The knnForecast object.

highlight

A string value indicating what elements should be highlighted. Possible values are "none", "points" and "neighbors".

faceting

Logical. This applies only if the highlight parameter is set to "neighbors". It indicates whether the different nearest neighbors should be seen in different plots (TRUE) or in one plot.

Examples

Run this code
pred <- knn_forecasting(USAccDeaths, h = 12, lags = 1:12, k = 2)
library(ggplot2)
autoplot(pred)
autoplot(pred, highlight = "neighbors")

Run the code above in your browser using DataLab