This notebook illustrates the usage of tsibble datasets.
library(tsibble) library(feasts) library(dplyr) library(ggplot2) library(lubridate) library(tidyr)
tourists_tsbl <- tdvhackaviz2020::tourists_tsbl() tourists_tsbl
top_3 <- tourists_tsbl %>% group_by_key() %>% index_by(year_month = ~ year(.)) %>% # monthly aggregates summarise( capa = mean(capa, na.rm = TRUE), nuitees = mean(nuitees, na.rm = TRUE), diff = capa - nuitees ) %>% arrange(desc(nuitees)) %>% top_n(3, nuitees) top_3
tourists_tsbl %>% filter(dep %in% top_3$dep) %>% gg_season(capa)
tourists_tsbl() %>% filter(dep %in% top_3$dep) %>% ggplot(aes(x = date, y = nuitees)) + geom_line(aes(y = capa, col = "capa")) + geom_line(aes(y = nuitees, col = "nuitees")) + facet_grid(dep ~ .)
nuitees_plot <- tdvhackaviz2020::nuitees_tsbl() %>% filter(dep %in% top_3$dep) %>% ggplot(aes(x = date, y = nuitees, group=dep)) + geom_line(aes(col = dep)) nuitees_plot
A simple way to plot holidays from tidy data.
tdvhackaviz2020::vacances_tsbl() %>% mutate(vacances = as.numeric(vacances) * 100) %>% ggplot(aes(x = date, y = vacances, group = zone)) + scale_fill_grey() + geom_area(aes(fill=zone), position=position_dodge(1), alpha = 0.5) + theme_minimal()
Use with another plot.
nuitees_tsbl = tdvhackaviz2020::nuitees_tsbl() # Converting logical to numeric values vacances_tsbl <- tdvhackaviz2020::vacances_tsbl() %>% mutate(vacances = as.numeric(vacances) * max(nuitees_tsbl$nuitees , na.rm = TRUE)) nuitees_tsbl %>% ggplot(aes(x = date, y = nuitees, group=dep)) + geom_line(aes(col = dep)) + scale_fill_grey() + geom_area(data = vacances_tsbl, aes(x = date, y = vacances, group = zone, fill= zone), position=position_dodge(1), alpha = 0.2) + theme_minimal()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.