View source: R/geom_epicurve.R
geom_epicurve | R Documentation |
Creates a epicurve plot for visualizing epidemic case counts in outbreaks (epidemiological curves).
An epicurve is a bar plot, where every case is outlined. geom_epicurve
additionally provides
date-based aggregation of cases (e.g. per week or month and many more).
For week aggregation both isoweek (World + ECDC) and epiweek (US CDC) are supported.
stat_bin_date
and its alias stat_date_count
provide date based binning only. After binning the by date, these
stats behave like ggplot2::stat_count.
geom_epicurve(
mapping = NULL,
data = NULL,
stat = "epicurve",
position = "stack",
date_resolution = NULL,
week_start = getOption("lubridate.week.start", 1),
width = NULL,
relative.width = 1,
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
stat_bin_date(
mapping = NULL,
data = NULL,
geom = "line",
position = "identity",
date_resolution = NULL,
week_start = getOption("lubridate.week.start", 1),
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
stat_date_count(
mapping = NULL,
data = NULL,
geom = "line",
position = "identity",
date_resolution = NULL,
week_start = getOption("lubridate.week.start", 1),
...,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by
|
data |
The data frame containing the variables for the plot |
stat |
either " |
position |
Position adjustment. Currently supports " |
date_resolution |
Character string specifying the time unit for date aggregation.
Set to
|
week_start |
Integer specifying the start of the week (1 = Monday, 7 = Sunday). |
width |
Numeric value specifying the width of the bars. If |
relative.width |
Numeric value between 0 and 1 adjusting the relative width of bars. Defaults to 1 |
... |
Other arguments passed to
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use to display the data for this layer.
When using a |
Epi Curves are a public health tool for outbreak investigation. For more details see the references.
A ggplot2
geom layer that can be added to a plot
Centers for Disease Control and Prevention. Quick-Learn Lesson: Using an Epi Curve to Determine Mode of Spread. USA. https://www.cdc.gov/training/quicklearns/epimode/
Dicker, Richard C., Fátima Coronado, Denise Koo, and R. Gibson Parrish. 2006. Principles of Epidemiology in Public Health Practice; an Introduction to Applied Epidemiology and Biostatistics. 3rd ed. USA. https://stacks.cdc.gov/view/cdc/6914
scale_y_cases_5er()
, geom_vline_year()
# 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(break_type = "week") +
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.