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

label_number_si

Label numbers with SI prefixes (2k, 1M, 5T etc)


Description

number_si() automatically scales and labels with the best SI prefix, "K" for values 10e3, "M" for 10e6, "B" for 10e9, and "T" for 10e12.

Usage

label_number_si(accuracy = 1, unit = NULL, sep = NULL, ...)

Arguments

accuracy

A number to round to. Use (e.g.) 0.01 to show 2 decimal places of precision. If NULL, the default, uses a heuristic that should ensure breaks have the minimum number of digits needed to show the difference between adjacent values.

Applied to rescaled data.

unit

Optional units specifier.

sep

Separator between number and SI unit. Defaults to " " if units is supplied, and "" if not.

...

Other arguments passed on to base::format().

Value

All label_() functions return a "labelling" function, i.e. a function that takes a vector x and returns a character vector of length(x) giving a label for each input value.

Labelling functions are designed to be used with the labels argument of ggplot2 scales. The examples demonstrate their use with x scales, but they work similarly for all scales, including those that generate legends rather than axes.

See Also

Other labels for log scales: label_bytes(), label_scientific()

Examples

demo_continuous(c(1, 1e9), label = label_number_si())
demo_continuous(c(1, 5000), label = label_number_si(unit = "g"))
demo_continuous(c(1, 1000), label = label_number_si(unit = "m"))

demo_log10(c(1, 1e9), breaks = log_breaks(10), labels = label_number_si())

scales

Scale Functions for Visualization

v1.1.1
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre], Dana Seidel [aut], RStudio [cph]
Initial release

We don't support your browser anymore

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