scale_x_dt: Date Scale

View source: R/axis_scales.R

scale_x_dtR Documentation

Date Scale

Description

Wrapper for ggplot2::scale_x_date that generates labels for data variable on x-axis based on input data.

Usage

scale_x_dt(
  df,
  x,
  break_by = "year",
  round_unit = "year",
  labels = scales::date_format("'%y"),
  ...
)

Arguments

df

data set used for plotting

x

date variable mapped to x-axis

break_by

a character string specifying a time unit to use for axis breaks

round_unit

a character string specifying a time unit or a multiple of a unit to be rounded to for the axis breaks. Valid base units are second, minute, hour, day, week, month, bimonth, quarter, season, halfyear and year.

labels

format to use for displaying labels

...

additional arguments passed to ggplot2::scale_x_date

Value

A ggplot2 date scale object created by ggplot2::scale_x_date().

Author(s)

Saannidhya Rawat

Examples



library(ggplot2)

# use default ggplot2 scale
bcat_plt_line(df = economics,
              x = date,
              y = unemploy,
              y_ref = 10000)

# use scale_x_dt to break by every 5 years
bcat_plt_line(df = economics,
              x = date,
              y = unemploy,
              y_ref = 10000,
              x_scale = scale_x_dt(economics, date, round_unit = "5 years"))

Rbearcat documentation built on March 21, 2026, 5:07 p.m.