pretty10exp | R Documentation |
Produce nice a \times 10^k
expressions to be used
instead of the scientific notation "a E<k>"
.
pretty10exp(x, drop.1 = FALSE, sub10 = FALSE, digits = 7, digits.fuzz,
off = pmax(10^-digits, 2^-(l10x*log2(10)+1075)),
lab.type = c("plotmath","latex"),
lab.sep = c("cdot", "times"))
x |
numeric vector (e.g. axis tick locations) |
drop.1 |
logical indicating if |
sub10 |
logical, Special cases: |
digits |
number of digits for mantissa ( |
digits.fuzz |
the old deprecated name for |
off |
a numeric offset in |
lab.type |
a string indicating how the result should look like.
By default, ( |
lab.sep |
character separator between mantissa and exponent for LaTeX labels; it will be prepended with a backslash, i.e., ‘"cdot"’ will use ‘"\cdot"’ |
For the default lab.type = "plotmath"
,
an expression of the same length as x
, typically with elements
of the form a %*% 10 ^ k
.
Exceptions are 0
which is kept simple, if drop.1
is
true and a = 1
, 10 ^ k
is used, and if sub10
is not false, a %*% 10 ^ 0
as a
, and a %*% 10 ^ k
as
as the corresponding formatted number a * 10^k
independently of
drop.1
.
Otherwise, a character
vector of the same length as
x
. For lab.type = "latex"
, currently the only
alternative to the default, these strings are LaTeX (math mode)
compatible strings.
If sub10
is set, it will typically be a small number such as 0,
1, or 2. Setting sub10 = TRUE
will be interpreted as
sub10 =1
where resulting exponents k
will either be
negative or k \ge 2
.
Martin Maechler; Ben Bolker contributed lab.type = "latex"
and lab.sep
.
axTexpr
and eaxis()
which build on
pretty10exp()
, notably the eaxis()
example plots.
The new toLatex.numeric
method which gives very similar
results with option scientific = TRUE
.
Further, axis
, axTicks
.
pretty10exp(-1:3 * 1000)
pretty10exp(-1:3 * 1000, drop.1 = TRUE)
pretty10exp(c(1,2,5,10,20,50,100,200) * 1e3)
pretty10exp(c(1,2,5,10,20,50,100,200) * 1e3, drop.1 = TRUE)
set.seed(17); lx <- rlnorm(10, m=8, s=6)
pretty10exp(lx, digits = 3)
pretty10exp(lx, digits = 3, sub10 = 2)
pretty10exp(lx, digits = 3, lab.type="latex")
pretty10exp(lx, digits = 3, lab.type="latex", lab.sep="times", sub10=2)
## use regular formatted numbers from 0.03 to 300 :
pretty10exp(3*10^(-3:4), sub10 = c(-2,2))
pretty10exp(3*10^(-3:4), sub10 = c(-2,2), lab.type = "l")
ax <- 10^(-6:0) - 2e-16
pretty10exp(ax, drop.1=TRUE) # nice for plotting
pretty10exp(ax, drop.1=TRUE, sub10=TRUE)
pretty10exp(ax, drop.1=TRUE, sub10=c(-2,2))
## in sfsmisc version <= 1.0-16, no 'digits',
## i.e., implicitly had digits := #{double precision digits} ==
(dig. <- .Machine$double.digits * log10(2)) # 15.95
pretty10exp(ax, drop.1=TRUE, digits= dig.) # ''ugly''
## Subnormal numbers
x <- sort(c(outer(10^-(323:305), 1:9))); x <- c(x[1]/2, x)
tail(x, 12) # nice
head(x, 6) # "ugly" (they are multiple's of 2^-1074):
head(x, 6) / 2^-1074 # nice
head(p0 <- pretty10exp(x, off = 10^-7), 30) # previous behavior {before 'off' existed}
str(head(pTen <- lapply(p0, `[[`, 3L)))
str(exTen <- sapply(pTen, `[[`, 3L)) # -324 -324 ..
head(f0 <- sapply(p0, `[[`, 2L), 17)
head(p1 <- pretty10exp(x))# new default
str(head(pTen1 <- lapply(p1, `[[`, 3L)))
str(exTen1 <- sapply(pTen1, `[[`, 3L)) # -324 -324 ..
head(f1 <- sapply(p1, `[[`, 2L), 17) #
head(cbind(x, f0, f1, exTen, exTen1), 80)
(nEQ <- which(sapply(1:length(p0), function(i) p0[[i]] != p1[[i]])))
cbind(x, f0, f1, exTen, exTen1)[nEQ,]
stopifnot(is.finite(f1), 0.5 <= f1, f1 <= 9)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.