label_number | R Documentation |
Use label_number()
force decimal display of numbers (i.e. don't use
scientific notation). label_comma()
is a special case
that inserts a comma every three digits.
label_number( accuracy = NULL, scale = 1, prefix = "", suffix = "", big.mark = " ", decimal.mark = ".", style_positive = c("none", "plus"), style_negative = c("hyphen", "minus", "parens"), scale_cut = NULL, trim = TRUE, ... ) label_comma( accuracy = NULL, scale = 1, prefix = "", suffix = "", big.mark = ",", decimal.mark = ".", trim = TRUE, digits, ... )
accuracy |
A number to round to. Use (e.g.) Applied to rescaled data. |
scale |
A scaling factor: |
prefix |
Additional text to display before the number. The suffix is
applied to absolute value before |
suffix |
Additional text to display after the number. |
big.mark |
Character used between every 3 digits to separate thousands. |
decimal.mark |
The character to be used to indicate the numeric decimal point. |
style_positive |
A string that determines the style of positive numbers:
|
style_negative |
A string that determines the style of negative numbers:
|
scale_cut |
Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include:
If you supply a vector |
trim |
Logical, if |
... |
Other arguments passed on to |
digits |
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.
demo_continuous(c(-1e6, 1e6)) demo_continuous(c(-1e6, 1e6), labels = label_number()) demo_continuous(c(-1e6, 1e6), labels = label_comma()) # Use scale to rescale very small or large numbers to generate # more readable labels demo_continuous(c(0, 1e6), labels = label_number()) demo_continuous(c(0, 1e6), labels = label_number(scale = 1 / 1e3)) demo_continuous(c(0, 1e-6), labels = label_number()) demo_continuous(c(0, 1e-6), labels = label_number(scale = 1e6)) #' Use scale_cut to automatically add prefixes for large/small numbers demo_log10( c(1, 1e9), breaks = log_breaks(10), labels = label_number(scale_cut = cut_short_scale()) ) demo_log10( c(1, 1e9), breaks = log_breaks(10), labels = label_number(scale_cut = cut_si("m")) ) demo_log10( c(1e-9, 1), breaks = log_breaks(10), labels = label_number(scale_cut = cut_si("g")) ) # use scale and scale_cut when data already uses SI prefix # for example, if data was stored in kg demo_log10( c(1e-9, 1), breaks = log_breaks(10), labels = label_number(scale_cut = cut_si("g"), scale = 1e3) ) #' # Use style arguments to vary the appearance of positive and negative numbers demo_continuous(c(-1e3, 1e3), labels = label_number( style_positive = "plus", style_negative = "minus" )) demo_continuous(c(-1e3, 1e3), labels = label_number(style_negative = "parens")) # You can use prefix and suffix for other types of display demo_continuous(c(32, 212), labels = label_number(suffix = "\u00b0F")) demo_continuous(c(0, 100), labels = label_number(suffix = "\u00b0C"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.