Skip to content

Switches between number_format() and scientific_format() based on a set of heuristics designed to automatically generate useful labels across a wide range of inputs

Usage

label_number_auto()

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

Examples

# Very small and very large numbers get scientific notation
demo_continuous(c(0, 1e-6), labels = label_number_auto())
#> scale_x_continuous(labels = label_number_auto())

demo_continuous(c(0, 1e9), labels = label_number_auto())
#> scale_x_continuous(labels = label_number_auto())


# Other ranges get the numbers printed in full
demo_continuous(c(0, 1e-3), labels = label_number_auto())
#> scale_x_continuous(labels = label_number_auto())

demo_continuous(c(0, 1), labels = label_number_auto())
#> scale_x_continuous(labels = label_number_auto())

demo_continuous(c(0, 1e3), labels = label_number_auto())
#> scale_x_continuous(labels = label_number_auto())

demo_continuous(c(0, 1e6), labels = label_number_auto())
#> scale_x_continuous(labels = label_number_auto())


# Transformation is applied individually so you get as little
# scientific notation as possible
demo_log10(c(1, 1e7), labels = label_number_auto())
#> scale_x_log10(labels = label_number_auto())