precision_prefix: Suggested precision for SI Prefix formatting

Description Usage Arguments Details Value Source See Also Examples

Description

The function precision_prefix_ provides a suggested precision for use with SI prefix to use, given a value to format, and the difference between the values, step, that will be formatted. precision_prefix calculates the suggested SI Prefix given a numeric vector of values to format, x.

Usage

1
2
3

Arguments

x

A numeric vector of values to be formatted.

prefix

The SI prefix to use. This is any valid argument for si_prefix. If NULL in precision_prefix, then the prefix is determined from the median value in x.

step

Numeric: Minimum absolute difference between values that will be formatted.

Details

The suggested precision, p, when formatting a vector with an SI Prefix of 10^k is,

p = max(0, floor(log10(d))),

where d is the maximum absolute value between elements in the vector.

Value

Named list of two elements:

precision

Integer vector: The suggested precision

si_prefix

An named integer vector of SI prefixes. The names are the SI prefix names, and the values are the exponents, as in SI_PREFIXES.

Source

The d3-format function precisionPrefix.

See Also

precision_fixed for the suggested precision to use with formats that use a fixed number of digits after the decimal point, and precision_round for the suggested precision to use with formats that round to significant digits.

Examples

1
2
3
4
x <- c(1.1e6, 1.2e6, 1.3e6)
p <- precision_prefix(x, 6L)
p$precision
fmt(x, paste0(".", p$precision), si_prefix = 6L)

jrnold/fivemat documentation built on May 20, 2019, 1 a.m.