scale_x_grates_isoweek: Isoweek scale

View source: R/isoweek-scale.R

scale_x_grates_isoweekR Documentation

Isoweek scale

Description

ggplot2 scale for an ⁠<grates_isoweek>⁠ vector.

Usage

scale_x_grates_isoweek(
  ...,
  breaks = ggplot2::waiver(),
  n.breaks = 6L,
  format = NULL
)

Arguments

...

Not currently used.

breaks

A ⁠<grates_isoweek>⁠ vector of the desired breaks.

n.breaks

⁠[integer]⁠

Approximate number of breaks calculated using scales::breaks_pretty (default 6L).

Will only have an effect if breaks = waiver().

format

Format to use if "Date" scales are required.

If NULL (default) then labels are in the standard isoweek format (YYYY-Www).

If "week" then the labels are of the form Www (e.g. W37).

Otherwise the value is used by format.Date() and can be any input acceptable by that function.

Value

A scale for use with ggplot2.

Examples



# use simulated linelist data from the outbreaks package
linelist <- outbreaks::ebola_sim_clean$linelist
x <- as_isoweek(linelist$date_of_infection)
dat <- aggregate(list(cases = x), by = list(week = x), FUN = length)

# plot the output
(week_plot <-
    ggplot2::ggplot(dat, ggplot2::aes(week, cases)) +
    ggplot2::geom_col(width = 1, colour = "white") +
    ggplot2::theme_bw())

# We can have non-centred date labels on the x_axis by using the
# associated scale function and explicitly specifying a format for
# the date labels:
week_plot + scale_x_grates_isoweek(format = "%Y-%m-%d")


grates documentation built on April 3, 2025, 10:49 p.m.