Description Usage Arguments Details Value Source See Also Examples
Take either a numeric vector or the maximum absolute step
size
between values and and return a suggested decimal precision for fixed
point formats such as "f"
.
1 2 3 |
x |
A numeric vector to be formatted. |
step |
Minimum absolute difference between values that will be formatted. |
precision_round
Returns a suggested decimal precision for format types
that round to significant digits, such as "g"
and "r"
.
precision_fixed
Returns a suggested SI prefix.
The suggested precision is
max(0, floor(log10(d)))
where d is the maximum absolute distance between values.
This assumes that the values to be formatted are multiples of the step
size d
.
An integer vector of suggest precisions. For precision_fixed
,
this is length one, for precision_fixed_
it is the same length
as step
.
The d3-format
function precisionFixed.
precision_round
for the suggested precision to
use with formats that round to significant digits,
and precision_prefix
for the suggested SI prefix to use with
formatting.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # step size is 1 and the suggested precision is 0
x <- c(1, 1.5, 2)
p <- precision_fixed(x)
p
fmt(x, paste0(".", p, "f"))
# alternatively calculate the step size
step <- max(diff(sort(x)))
precision_fixed_(step)
# For 1, 2, 3, the step size is 1 suggested precision is 0
x2 <- 1:3
p2 <- precision_fixed(x2)
p2
fmt(x2, paste0(".", p, "f"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.