Determines turn of year dates based on the range of either the x or y axis of the ggplot.
geom_vline_year()
draws vertical lines at the turn of each yeargeom_hline_year()
draws horizontal lines at the turn of each year
Usage
geom_vline_year(
mapping = NULL,
position = "identity",
year_break = "01-01",
just = -0.5,
...,
show.legend = NA
)
geom_hline_year(
mapping = NULL,
position = "identity",
year_break = "01-01",
just = -0.5,
...,
show.legend = NA
)
Arguments
- mapping
Mapping created using
ggplot2::aes()
. Can be used to add the lines to the legend. E.g.aes(linetype = 'End of Year')
. Cannot access data specified inggplot2::ggplot()
. Panels created byggplot2::facet_wrap()
orggplot2::facet_grid()
are available withaes(linetype = PANEL)
.- position
Position adjustment, either as a string, or the result of a call to a position adjustment function.
- year_break
String specifying the month and day of the year break ("MM-DD"). Defaults to:
"01-01"
for January 1.- just
Numeric offset in days (justification). Shifts the lines from the year break date. Defaults to
-0.5
, which shifts the line by half a day so if falls in the middle between December 31 and January 1.- ...
Other arguments passed to
layer
. For example:colour
Colour of the line. Try:colour = "grey50"
linetype
Linetype. Try:linetype = "dashed"
orlinetype = "dotted"
linewidth
Width of the line.alpha
Transparency of the line. used to set an aesthetic to a fixed value, likecolour = "grey25"
orlinetype = 2
.
- show.legend
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.FALSE
never includes, andTRUE
always includes.
Examples
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_epicurve(date_resolution = "week") +
geom_vline_year(year_break = "01-01", show.legend = TRUE) +
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
theme_bw()