Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

xgx_scale_x_time_units

Convert time units for plotting


Description

xgx_scale_x_time_units converts x axis scale from one time unit to another. Supported units include hours, days, weeks, months, and years, which can also be called using just the first letter (h, d, w, m, y).

Usage

xgx_scale_x_time_units(
  units_dataset,
  units_plot = NULL,
  breaks = NULL,
  labels = NULL,
  ...
)

xgx_scale_y_time_units(
  units_dataset,
  units_plot = NULL,
  breaks = NULL,
  labels = NULL,
  ...
)

Arguments

units_dataset

units of the input dataset, must be specified by user as "h", "d", "w", "m", or "y"

units_plot

units of the plot, will be units of the dataset if empty

breaks

One of:

  • NULL for no breaks

  • waiver() for the default breaks computed by the transformation object

  • A numeric vector of positions

  • A function that takes the limits as input and returns breaks as output (e.g., a function returned by scales::extended_breaks())

labels

One of:

  • NULL for no labels

  • waiver() for the default labels computed by the transformation object

  • A character vector giving labels (must be same length as breaks)

  • A function that takes the breaks as input and returns labels as output

...

other parameters for scale_x_continuous

Details

Note: xgx_scale_x_time_units only scales the plot axis, all other specifications must be on the original scale of the dataset (e.g. breaks, position, width)

Value

ggplot2 compatible scale object

Examples

data <- data.frame(x = 1:1000, y = rnorm(1000))
ggplot2::ggplot(data = data, ggplot2::aes(x = x, y = y)) +
  ggplot2::geom_point() +
  xgx_scale_x_time_units(units_dataset = "hours", units_plot = "weeks")

xgxr

Exploratory Graphics for Pharmacometrics

v1.1.1
MIT + file LICENSE
Authors
Andrew Stein [aut, cre], Alison Margolskee [aut], Fariba Khanshan [aut], Konstantin Krismer [aut] (<https://orcid.org/0000-0001-8994-3416>), Matthew Fidler [ctb] (<https://orcid.org/0000-0001-8538-6691>), Novartis Pharma AG [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.