Plots one or more series over time, with an optional moving-average overlay.
The input can be a ts object, a numeric vector, or a data frame with a time
column, a value column and an optional grouping column.
Usage
timeseries_plot(
x,
time = NULL,
value = NULL,
group = NULL,
rolling = NULL,
forecast = NULL,
frequency = NULL,
level = 0.95,
palette = NULL,
point = FALSE,
title = NULL,
x_lab = NULL,
y_lab = NULL
)Arguments
- x
A
tsobject, a numeric vector, or a data frame.- time
When
xis a data frame, the time column (string or unquoted name); whenxis a numeric vector, an optional vector of times.- value
When
xis a data frame, the value column.- group
When
xis a data frame, an optional grouping column mapped to colour.- rolling
Optional integer window for a centred moving-average overlay. The data are ordered by time (within each group) before the moving average is computed, so unsorted input is handled correctly.
- forecast
Optional forecast overlay for a single (non-grouped) series. Either an integer horizon (number of future steps) to forecast with the built-in STL + seasonal-naive-with-drift method (see
ts_forecast()), or a pre-computed forecast supplied as a data frame with columnstime,fitand (optionally)lwr/upr, for instance from a fittedforecast::forecast()object. The point forecast continues the line and a shaded prediction-interval ribbon, which widens with the horizon, is drawn behind it.- frequency
Number of observations per period, used only to coerce a numeric
xto atswhen an integerforecasthorizon is requested.- level
Prediction-interval coverage for the built-in forecast (a single number strictly between 0 and 1, e.g.
0.95).- palette
Colours for the groups; defaults to
depictr_palette().- point
Whether to add points as well as the line.
- title, x_lab, y_lab
Title and axis labels.
Value
A ggplot2::ggplot object.


