grates provides a simple and coherent implementation of grouped date classes, including:
as_yrwk()
) with arbitrary first day of the week;as_yrmon()
);as_yrqtr()
); andas_period()
) of arbitrary length.You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("tjtnew/grates")
library(outbreaks)
library(dplyr)
library(tidyr)
library(ggplot2)
library(grates)
dat <- ebola_sim_clean$linelist
dat %>%
mutate(date = as_yrwk(date_of_infection, firstday = 2)) %>%
count(date, name = "cases") %>%
drop_na() %>%
ggplot(aes(date, cases)) + geom_col() + theme_bw() + xlab("")
dat %>%
mutate(date = as_yrmon(date_of_infection)) %>%
count(date, name = "cases") %>%
drop_na() %>%
ggplot(aes(date, cases)) + geom_col() + theme_bw() + xlab("")
dat %>%
mutate(date = as_yrqtr(date_of_infection)) %>%
count(date, name = "cases") %>%
drop_na() %>%
ggplot(aes(date, cases)) +
geom_col() +
theme_bw() +
xlab("")
dat %>%
mutate(date = as_period(date_of_infection, interval = 20)) %>%
count(date, name = "cases") %>%
drop_na() %>%
ggplot(aes(date, cases)) + geom_col() + theme_bw() + xlab("")
dat %>%
mutate(date = as_period(date_of_infection, interval = "10 days")) %>%
count(date, name = "cases") %>%
drop_na() %>%
ggplot(aes(date, cases)) + geom_col() + theme_bw() + xlab("")
dat %>%
mutate(date = as_period(date_of_infection, interval = "1 week")) %>%
count(date, name = "cases") %>%
drop_na() %>%
ggplot(aes(date, cases)) + geom_col() + theme_bw() + xlab("")
dat %>%
mutate(date = as_period(date_of_infection, interval = "2 months")) %>%
count(date, name = "cases") %>%
drop_na() %>%
ggplot(aes(date, cases)) + geom_col() + theme_bw() + xlab("")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.