axTexpr: Axis Ticks Expressions in Nice 10 ** k Form

View source: R/prettylab.R

axTexprR Documentation

Axis Ticks Expressions in Nice 10 ** k Form

Description

Produce nice a \times 10^k expressions for axis labeling instead of the scientific notation "a E<k>".

Usage

axTexpr(side, at = axTicks(side, axp = axp, usr = usr, log = log),
        axp = NULL, usr = NULL, log = NULL,
        drop.1 = FALSE)

Arguments

side

integer in 1:4 specifying the axis side, as for axis.

at

numeric vector; with identical default as in axTicks().

axp, usr, log

as for axTicks().

drop.1

logical indicating if 1 \times should be dropped from the resulting expressions.

Details

This is just a utility with the same arguments as axTicks, a wrapper pretty10exp(at, *).

Value

an expression of the same length as x, with elements of the form a %*% 10 ^ k.

Author(s)

Martin Maechler

See Also

pretty10exp; eaxis, axis, axTicks.

Examples

x <- 1e7*(-10:50)
y <- dnorm(x, m=10e7, s=20e7)
plot(x,y)## not really nice,  the following is better:

## For horizontal y-axis labels, need more space:
op <- par(mar= .1+ c(5,5,4,1))
plot(x,y, axes= FALSE, frame=TRUE)
aX <- axTicks(1); axis(1, at=aX, label= axTexpr(1, aX))
## horizontal labels on y-axis:
aY <- axTicks(2); axis(2, at=aY, label= axTexpr(2, aY), las=2)
par(op)

### -- only 'x' and using log-scale there:
plot(x,y, xaxt= "n", log = "x")
aX <- axTicks(1); axis(1, at=aX, label= axTexpr(1, aX))

## Now an "engineer's version" ( more ticks; only label "10 ^ k" ) :

axp <- par("xaxp") #-> powers of 10 *inside* 'usr'
axp[3] <- 1 # such that only 10^. are labeled
aX <- axTicks(1, axp = axp)
xu <- 10 ^ par("usr")[1:2]
e10 <- c(-1,1) + round(log10(axp[1:2])) ## exponents of 10 *outside* 'usr'
v <- c(outer(1:9, e10[1]:e10[2], function(x,E) x * 10 ^ E))
v <- v[xu[1] <= v & v <= xu[2]]

plot(x,y, xaxt= "n", log = "x", main = "engineer's version of x - axis")
axis(1, at = aX, label = axTexpr(1, aX, drop.1=TRUE)) # 'default'
axis(1, at = v,  label = FALSE, tcl = 2/3 * par("tcl"))

mmaechler/sfsmisc documentation built on Feb. 28, 2024, 4:18 a.m.