if(require(outbreaks) && require(ggplot2)) { withAutoprint({
onset <- outbreaks::ebola_sim$linelist$date_of_onset
## daily incidence
inc <- incidence(onset)
inc
plot(inc)
## weekly incidence
inc.week <- incidence(onset, interval = 7)
inc.week
plot(inc.week) # default to label x axis tick marks with isoweeks
plot(inc.week, labels_week = FALSE) # label x axis tick marks with dates
plot(inc.week, border = "white") # with visible border
## use group information
sex <- outbreaks::ebola_sim$linelist$gender
inc.week.gender <- incidence(onset, interval = "1 epiweek", groups = sex)
plot(inc.week.gender)
plot(inc.week.gender, labels_week = FALSE)
## show individual cases at the beginning of the epidemic
inc.week.8 <- subset(inc.week.gender, to = "2014-06-01")
p <- plot(inc.week.8, show_cases = TRUE, border = "black")
p
## update the range of the scale
lim <- c(min(get_dates(inc.week.8)) - 7*5,
aweek::week2date("2014-W50", "Sunday"))
lim
p + scale_x_incidence(inc.week.gender, limits = lim)
## customize plot with ggplot2
plot(inc.week.8, show_cases = TRUE, border = "black") +
theme_classic(base_size = 16) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
## adding fit
fit <- fit_optim_split(inc.week.gender)$fit
plot(inc.week.gender, fit = fit)
plot(inc.week.gender, fit = fit, labels_week = FALSE)
})}
Run the code above in your browser using DataLab