Skip to contents

Dynamically determines the appropriate Y-axis breaks, labels, and title based on the maximum value in a vector of numeric data. Used to standardize axis formatting across plots.

Usage

set_axis(values, units = "Persons")

Arguments

values

A numeric vector. Typically, a column of values to be plotted.

units

A character string describing the units of measurement (e.g., "Persons", "USD").

Value

A list with components:

  • breaks — Either a numeric vector or waiver().

  • labels — A labeling function or character vector.

  • title — A character string for axis title.

Examples

set_axis(c(100, 500, 1000), units = "Persons")
#> $breaks
#> list()
#> attr(,"class")
#> [1] "waiver"
#> 
#> $labels
#> list()
#> attr(,"class")
#> [1] "waiver"
#> 
#> $title
#> [1] "Persons"
#> 
set_axis(c(5e8, 1.5e9), units = "USD")
#> $breaks
#> [1] 0.0e+00 5.0e+08 1.0e+09 1.5e+09
#> 
#> $labels
#> [1] "0"   "0.5" "1.0" "1.5"
#> 
#> $title
#> [1] "Billions USD"
#>