## EXAMPLE 1:
set.seed(1234)
dat <- rpois(n = 50, lambda = 2)
dat.edr01 <- epi.edr(dat, n = 4, conf.level = 0.95, nsim = 99, na.zero = TRUE)
sdate <- as.Date(x = "31/12/2015", format = "%d/%m/%Y") + 1:50
dat.df01 <- data.frame(sdate = sdate, est = dat.edr01$est,
low = dat.edr01$lower, upp = dat.edr01$upper)
## Line plot of EDR (and its 95% confidence interval) as a function of
## calendar time:
if (FALSE) {
library(ggplot2); library(scales)
ggplot() +
geom_line(data = dat.df01, aes(x = sdate, y = est)) +
geom_line(dat = dat.df01, aes(x = sdate, y = upp), lty = 3, size = 0.5) +
geom_line(dat = dat.df01, aes(x = sdate, y = low), lty = 3, size = 0.5) +
scale_x_date(breaks = date_breaks("1 week"),
labels = date_format("%d %b"), name = "Date") +
scale_y_continuous(trans = "log2", breaks = c(0.25,0.5,1,2,4,8,16),
limits = c(0.25,16),name = "Estimated disemination ratio (EDR)") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, size = 10)) +
geom_hline(yintercept = 1, lty = 2)
}
Run the code above in your browser using DataLab