pretty_sci: Print scientific numbers

View source: R/plot_extra.R

pretty_sciR Documentation

Print scientific numbers

Description

Functions to parse numeric vectors in scientific notation and return an expression for a pretty display.

Usage

pretty_sci(x, digits = 0L, base = 10, limit = base^3, simplify = TRUE)

oom(x, base = 10)

parse_sci(x, digits = 0L, base = 10, simplify = TRUE)

Arguments

x

a numeric vector

digits

integer indicating the number of decimal places to be used

base

a positive or complex number: the base with respect to which logarithms are computed (default is 10)

limit

a numeric value whose order of magnitude will set a limit beyond which values of x will be displayed in scientific notation; default is to display numbers beyond a magnitude of base^3; to display scientific notation always, use a negative value

simplify

logical; if TRUE (default), removes "1 x" from scientific format

Value

For oom an integer vector of magnitudes. For parse_sci an expression of values in scientific notation. For pretty_sci an expression of values in standard or scientific notation or combination depending on the value of limit.

See Also

pretty10exp; roundr; format; sprintf

Examples

x <- 10 ^ (1:5) / 10
oom(x)
oom(1 / x)

parse_sci(x)
parse_sci(x, simplify = FALSE)
parse_sci(x, base = 100)
parse_sci(1.1 * 2 ^ (1:5), 1, 2)

par(xpd = NA, mar = c(6,4,4,2) + .1)
plot(1:5, type = 'n', axes = FALSE, ann = FALSE)
axis(2, at = 1:5, labels = pretty_sci(x, simplify = FALSE), las = 1)

text(1:5, 0, pretty_sci(1 / x ^ 10))
text(1:5, 1, pretty_sci(1 / x, digits = 3))
text(1:5, 2, pretty_sci(1 / x, digits = 2, limit = 1e2))
text(1:5, 3, x)
text(1:5, 4, pretty_sci(x, limit = 1e2))
text(1:5, 5, pretty_sci(x, digits = 1))
text(1:5, 6, pretty_sci(x ^ 10))

text(1:5, -1, pretty_sci(1 / x, limit = -1, simplify = FALSE))


raredd/plotr documentation built on Nov. 19, 2023, 4:09 a.m.