library(ggplot2)
# Create sample epidemic curve data
epi_data <- data.frame(
date = rep(as.Date("2023-12-15") + 0:100, times = rpois(101, 2))
)
ggplot(epi_data, aes(x = date)) +
geom_epicurve(date_resolution = "week") +
scale_x_date(
date_breaks = "2 weeks", date_labels = "%d-%b-%Y",
guide = guide_axis_nested_date()
)
# Using fence type with ISO week labels
ggplot(epi_data, aes(x = date)) +
geom_epicurve(date_resolution = "week") +
scale_x_date(
date_breaks = "2 weeks", date_labels = "W%V.%G",
guide = guide_axis_nested_date(type = "fence")
)
# Using box type with custom padding
ggplot(epi_data, aes(x = date)) +
geom_epicurve(date_resolution = "month") +
scale_x_date(
date_breaks = "1 month", date_labels = "%b.%Y",
guide = guide_axis_nested_date(type = "box", pad_date = 0.3)
)
# Custom separator for different label formats
ggplot(epi_data, aes(x = date)) +
geom_epicurve(date_resolution = "week") +
scale_x_date(
date_breaks = "1 week", date_labels = "%d-%b-%Y",
guide = guide_axis_nested_date(type = "bracket", sep = "-")
)
# Datetime example with fence type
datetime_data <- data.frame(
datetime = rep(as.POSIXct("2024-02-05 01:00:00") + 0:50 * 3600,
times = rpois(51, 3)
)
)
ggplot(datetime_data, aes(x = datetime)) +
geom_epicurve(date_resolution = "2 hours") +
scale_x_datetime(
date_breaks = "6 hours", date_labels = "%Hh %e.%b",
limits = c(as.POSIXct("2024-02-04 22:00:00"), NA),
guide = guide_axis_nested_date()
)
Run the code above in your browser using DataLab