README.md

grates

Codecov test
coverage R-CMD-check

grates provides a simple and coherent implementation of grouped date classes, including:

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("tjtnew/grates")

Examples

library(outbreaks)
library(dplyr)
library(tidyr)
library(ggplot2)
library(grates) 

dat <- ebola_sim_clean$linelist

yrwk

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("")

yrmon

dat %>% 
  mutate(date = as_yrmon(date_of_infection)) %>% 
  count(date, name = "cases") %>% 
  drop_na() %>% 
  ggplot(aes(date, cases)) + geom_col() + theme_bw() + xlab("")

yrqtr

dat %>% 
  mutate(date = as_yrqtr(date_of_infection)) %>% 
  count(date, name = "cases") %>% 
  drop_na() %>% 
  ggplot(aes(date, cases)) + 
  geom_col() + 
  theme_bw() + 
  xlab("")

period

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("")



tjtnew/grates documentation built on Feb. 6, 2021, 6:12 p.m.