unit_format: Add units to the labels

Description Usage Arguments See Also Examples

View source: R/formatter.r

Description

Add units to the labels

Usage

1
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

1
2
3
4
5
6
7
# 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)

Example output

 [1] "0.66 km" "0.22 km" "0.70 km" "0.79 km" "0.46 km" "0.93 km" "0.49 km"
 [8] "0.45 km" "0.23 km" "0.81 km"
 [1] "7.3 km"  "60.6 km" "23.2 km" "84.2 km" "40.2 km" "44.1 km" "63.3 km"
 [8] "51.6 km" "95.2 km" "51.7 km"

scales documentation built on Aug. 24, 2017, 5:22 p.m.