breaks_right: Generate date breaks that align with the max limit

View source: R/breaks_right.R

breaks_rightR Documentation

Generate date breaks that align with the max limit

Description

This function generates a vector of of 'pretty' breaks (using scales::breaks_pretty()) that ends with the upper limit provided and excludes any values that lie outside the limits.

Usage

breaks_right(limits, n_breaks = 5, ...)

Arguments

limits

Length-two numeric or date vector

n_breaks

Number of breaks; passed to scales::breaks_pretty()

...

Passed to scales::breaks_pretty()

Value

Vector of breaks

Examples

# Can be used with numeric vectors
breaks_right(c(10, 30))

# Or date vectors
econ_dates <- c(min(ggplot2::economics$date),
               max(ggplot2::economics$date))
breaks_right(econ_dates)

# Can be supplied directly to the `breaks` argument of
# `ggplot2::scale_*_continuous()`, but limits will include
# padding defined by `expand`
library(ggplot2)

ggplot(ggplot2::economics,
      aes(x = date, y = unemploy)) +
 geom_line() +
 scale_x_date(breaks = breaks_right)


djpr-data/djprtheme documentation built on April 15, 2023, 2:47 a.m.