library(dplyr)
library(lubridate)
# Works with individual time series
FANG %>%
filter(symbol == "FB") %>%
plot_time_series(date, adjusted, .interactive = FALSE)
# Works with groups
FANG %>%
group_by(symbol) %>%
plot_time_series(date, adjusted,
.facet_ncol = 2, # 2-column layout
.interactive = FALSE)
# Can also group inside & use .color_var
FANG %>%
mutate(year = year(date)) %>%
plot_time_series(date, adjusted,
.facet_vars = c(symbol, year), # add groups/facets
.color_var = year, # color by year
.facet_ncol = 4,
.facet_scales = "free",
.facet_collapse = TRUE, # combine group strip text into 1 line
.interactive = FALSE)
# Can apply transformations to .value or .color_var
# - .value = log(adjusted)
# - .color_var = year(date)
FANG %>%
plot_time_series(date, log(adjusted),
.color_var = year(date),
.facet_vars = contains("symbol"),
.facet_ncol = 2,
.facet_scales = "free",
.y_lab = "Log Scale",
.interactive = FALSE)
Run the code above in your browser using DataLab