# Basic epicurve with dates
library(ggplot2)
set.seed(1)
plot_data_epicurve_imp <- data.frame(
date = rep(as.Date("2023-12-01") + ((0:300) * 1), times = rpois(301, 0.5))
)
ggplot(plot_data_epicurve_imp, aes(x = date, weight = 2)) +
geom_vline_year(year_break = "01-01", show.legend = TRUE) +
geom_epicurve(date_resolution = "week") +
labs(title = "Epicurve Example") +
scale_y_cases_5er() +
scale_x_date(date_breaks = "4 weeks", date_labels = "W%V'%g") + # Correct ISOWeek labels week'year
coord_equal(ratio = 7) + # Use coord_equal for square boxes. 'ratio' are the days per week.
theme_bw()
# Categorical epicurve
library(tidyr)
library(outbreaks)
sars_canada_2003 |> # SARS dataset from outbreaks
pivot_longer(starts_with("cases"), names_prefix = "cases_", names_to = "origin") |>
ggplot(aes(x = date, weight = value, fill = origin)) +
geom_epicurve(date_resolution = "week") +
scale_x_date(date_labels = "W%V'%g", date_breaks = "2 weeks") +
scale_y_cases_5er() +
theme_classic()
Run the code above in your browser using DataLab