library(tidyverse)
library(tidyquant)
library(lubridate)
library(timetk)
# Works with individual time series
FANG %>%
filter(symbol == "FB") %>%
plot_time_series_boxplot(
date, adjusted,
.period = "3 month",
.interactive = FALSE)
# Works with groups
FANG %>%
group_by(symbol) %>%
plot_time_series_boxplot(
date, adjusted,
.period = "3 months",
.facet_ncol = 2, # 2-column layout
.interactive = FALSE)
if (FALSE) {
# Can also group inside & use .color_var
FANG %>%
mutate(year = year(date)) %>%
plot_time_series_boxplot(
date, adjusted,
.period = "3 months",
.facet_vars = c(symbol, year), # add groups/facets
.color_var = year, # color by year
.facet_ncol = 4,
.facet_scales = "free",
.interactive = FALSE)
}
# Can apply transformations to .value or .color_var
# - .value = log(adjusted)
# - .color_var = year(date)
FANG %>%
plot_time_series_boxplot(
date, log(adjusted),
.period = "3 months",
.color_var = year(date),
.facet_vars = contains("symbol"),
.facet_ncol = 2,
.facet_scales = "free",
.y_lab = "Log Scale",
.interactive = FALSE)
# Can adjust the smoother
FANG %>%
group_by(symbol) %>%
plot_time_series_boxplot(
date, adjusted,
.period = "3 months",
.smooth = TRUE,
.smooth_func = median, # Smoother function
.smooth_period = "5 years", # Smoother Period
.facet_ncol = 2,
.interactive = FALSE)
Run the code above in your browser using DataLab