scales (version 0.4.0)

unit_format: Add units to the labels

Description

Add units to the labels

Usage

unit_format(unit = "m", scale = 1, sep = " ", ...)

Arguments

unit
The units to append
scale
A scaling factor. Useful if the underlying data is on another scale
sep
The separator between the number and the label
...
Arguments passed on to format

See Also

comma

Examples

Run this code
# labels in kilometer when the raw data are in meter
km <- unit_format(unit = "km", scale = 1e-3, digits = 2)
km(runif(10) * 1e3)

# labels in hectares, raw data in square meters
ha <- unit_format(unit = "ha", scale = 1e-4)
km(runif(10) * 1e5)

Run the code above in your browser using DataCamp Workspace