This function is a low-level helper that powers many of the labelling functions. You should generally not need to call it directly unless you are creating your own labelling function.
number(
x,
accuracy = NULL,
scale = 1,
prefix = "",
suffix = "",
big.mark = " ",
decimal.mark = ".",
style_positive = c("none", "plus", "space"),
style_negative = c("hyphen", "minus", "parens"),
scale_cut = NULL,
trim = TRUE,
...
)cut_short_scale(space = FALSE)
cut_long_scale(space = FALSE)
cut_time_scale(space = FALSE)
cut_si(unit)
A character vector of length(x)
.
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.
A scaling factor: x
will be multiplied by scale
before
formatting. This is useful if the underlying data is very small or very
large.
Additional text to display before the number. The suffix is
applied to absolute value before style_positive
and style_negative
are
processed so that prefix = "$"
will yield (e.g.) -$1
and ($1)
.
Additional text to display after the number.
Character used between every 3 digits to separate thousands.
The character to be used to indicate the numeric decimal point.
A string that determines the style of positive numbers:
"none"
(the default): no change, e.g. 1
.
"plus"
: preceded by +
, e.g. +1
.
"space"
: preceded by a Unicode "figure space", i.e., a space equally
as wide as a number or +
. Compared to "none"
, adding a figure space
can ensure numbers remain properly aligned when they are left- or
right-justified.
A string that determines the style of negative numbers:
"hyphen"
(the default): preceded by a standard hypen -
, e.g. -1
.
"minus"
, uses a proper Unicode minus symbol. This is a typographical
nicety that ensures -
aligns with the horizontal bar of the
the horizontal bar of +
.
"parens"
, wrapped in parentheses, e.g. (1)
.
Named numeric vector that allows you to rescale large (or small) numbers and add a prefix. Built-in helpers include:
cut_short_scale()
: [10^3, 10^6) = K, [10^6, 10^9) = M, [10^9, 10^12) = B, [10^12, Inf) = T.
cut_long_scale()
: [10^3, 10^6) = K, [10^6, 10^12) = M, [10^12, 10^18) = B, [10^18, Inf) = T.
cut_si(unit)
: uses standard SI units.
If you supply a vector c(a = 100, b = 1000)
, absolute values in the
range [0, 100)
will not be rescaled, absolute values in the range [100, 1000)
will be divided by 100 and given the suffix "a", and absolute values in
the range [1000, Inf)
will be divided by 1000 and given the suffix "b".
If the division creates an irrational value (or one with many digits), the
cut value below will be tried to see if it improves the look of the final
label.
Logical, if FALSE
, values are right-justified to a common
width (see base::format()
).
Other arguments passed on to base::format()
.
Add a space before the scale suffix?
SI unit abbreviation.