View source: R/plot-seasonal_diagnostics.R
plot_seasonal_diagnostics | R Documentation |
An interactive and scalable function for visualizing time series seasonality.
Plots are available in interactive plotly
(default) and static ggplot2
format.
plot_seasonal_diagnostics(
.data,
.date_var,
.value,
.facet_vars = NULL,
.feature_set = "auto",
.geom = c("boxplot", "violin"),
.geom_color = "#2c3e50",
.geom_outlier_color = "#2c3e50",
.title = "Seasonal Diagnostics",
.x_lab = "",
.y_lab = "",
.interactive = TRUE
)
.data |
A |
.date_var |
A column containing either date or date-time values |
.value |
A column containing numeric values |
.facet_vars |
One or more grouping columns that broken out into |
.feature_set |
One or multiple selections to analyze for seasonality. Choices include:
|
.geom |
Either "boxplot" or "violin" |
.geom_color |
Geometry color. Line color. Use keyword: "scale_color" to change the color by the facet. |
.geom_outlier_color |
Color used to highlight outliers. |
.title |
Plot title. |
.x_lab |
Plot x-axis label |
.y_lab |
Plot y-axis label |
.interactive |
If TRUE, returns a |
Automatic Feature Selection
Internal calculations are performed to detect a sub-range of features to include useing the following logic:
The minimum feature is selected based on the median difference between consecutive timestamps
The maximum feature is selected based on having 2 full periods.
Example: Hourly timestamp data that lasts more than 2 weeks will have the following features: "hour", "wday.lbl", and "week".
Scalable with Grouped Data Frames
This function respects grouped data.frame
and tibbles
that were made with dplyr::group_by()
.
For grouped data, the automatic feature selection returned is a collection of all features within the sub-groups. This means extra features are returned even though they may be meaningless for some of the groups.
Transformations
The .value
parameter respects transformations (e.g. .value = log(sales)
).
A plotly
or ggplot2
visualization
library(dplyr)
# ---- MULTIPLE FREQUENCY ----
# Taylor 30-minute dataset from forecast package
taylor_30_min
# Visualize series
taylor_30_min %>%
plot_time_series(date, value, .interactive = FALSE)
# Visualize seasonality
taylor_30_min %>%
plot_seasonal_diagnostics(date, value, .interactive = FALSE)
# ---- GROUPED EXAMPLES ----
# m4 hourly dataset
m4_hourly
# Visualize series
m4_hourly %>%
group_by(id) %>%
plot_time_series(date, value, .facet_scales = "free", .interactive = FALSE)
# Visualize seasonality
m4_hourly %>%
group_by(id) %>%
plot_seasonal_diagnostics(date, value, .interactive = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.