An extended axis() function which labels more prettily, in particular for log-scale axes.
It makes use of plotmath or (LaTeX) expressions of the form k∗10k for labeling a log-scaled axis and when otherwise exponential formatting would be used (see pretty10exp).
at: numeric vector of (normalsized ) tick locations; by default axTicks(side, ..), i.e., the same as axis() would use.
labels: NULL (default), logical, character or expression, as in axis(); in addition, if NA, labels = TRUE is passed to axis(), i.e. pretty10exp is not
used. Use FALSE to suppress any labeling.
log: logical or NULL specifying if log-scale should be used; the default depends on the current plot's axis.
use.expr: logical specifying if pretty10exp(.) should be used for constructing labels when they are NULL. The default is typically good enough, but you may occasionally force
use.expr = TRUE.
f.smalltcl: factor specifying the lengths of the small ticks in proportion to the normalsized, labeled ticks.
at.small: locations of small ticks; the default, NULL, uses small.mult and constructs smart
locations.
small.mult: positive integer (or NULL), used when at.small is NULL to indicate which multiples of at (typically axTicks()) should be used as small ticks . The default NULL will use 9 in the log case and a number in 2:5 otherwise.
equidist.at.tol: a small positive number, a tolerance to be used for checking equidistant at values. Used to be hardwired at .001 which was seen to be too small; increase it when necessary.
small.args: optional list of further arguments to the (second) axis() call which draws the small ticks.
draw.between.ticks: (only if log is true): logical indicating that possible (non-small) ticks between the labeled (via at) ones should be drawn as well (and possibly also used for at.small
construction), see also between.max.
between.max: (only if log and draw.between.ticks
are true): integer indicating ticks should be drawn (approximately) between the labeled ones.
outer.at: logical specifying that at.small should also be constructed outside the at range, but still inside the corresponding par("usr").
drop.1: logical specifying if 1∗ should be dropped from labels, passed to pretty10exp().
sub10: logical, integer (of length 1 or 2) or "10", indicating if some 10k should be simplified to traditional
formats, see pretty10exp.
nintLog: only used in > 2.13.x, when log is true: approximate (lower bound on) number of intervals for log scaling.
axp: to be passed to axTicks() if at is not specified.
n.axp: to be set to axp[3] when axp and at
are not specified, in order to tweak the number of (non-small) tick marks produced from axTicks(..), notably when log is true, set n.axp to 1, 2, or 3:
1:: will produce tick marks at 10j for integer j,
2:: gives marks k10j with kin1,5,
3:: gives marks k10j with kin1,2,5
see 'xaxp' on the par help page.
max.at: maximal number of at values to be used effectively. If you don't specify at yourself carefully, it is recommended to set this to something like 25, but this is not the default, for back compatibility reasons.
las, ...``: arguments passed to (the first) axis
call. Note that the default las = 1 differs from axis's default las = 0.
lab.type: string, passed to pretty10exp to choose between default plotmath or LaTeX label format.
lab.sep: separator between mantissa and exponent for LaTeX labels, see pretty10exp.
Author(s)
Martin Maechler
See Also
axis, axTicks, axTexpr, pretty10exp.
Examples
x <- lseq(1e-10,0.1, length =201)plot(x, pt(x, df=3), type ="l", xaxt ="n", log ="x")eaxis(1)## without small ticks:eaxis(3, at.small=FALSE, col="blue")## If you like the ticks, but prefer traditional (non-"plotmath") labels:plot(x, gamma(x), type ="l", log ="x")eaxis(1, labels=NA)x <- lseq(.001,0.1, length =1000)plot(x, sin(1/x)*x, type ="l", xaxt ="n", log ="x")eaxis(1)eaxis(3, n.axp =1)# -> xaxp[3] = 1: only 10^j (main) ticks## non- log-scale : draw small ticks, but no "10^k" if not needed:x <- seq(-100,100, length =1000)plot(x, sin(x)/x, type ="l", xaxt ="n")eaxis(1)# default -> {1, 2, 5} * 10^j tickseaxis(3, n.axp =2)# -> xaxp[3] := 2 -- approximately two (main) ticksx <- seq(-1,1, length =1000)plot(x, sin(x)/x, type ="l", xaxt ="n")eaxis(1, small.args = list(col="blue"))x <- x/1000plot(x,1-sin(x)/x, type ="l", xaxt ="n", yaxt ="n")eaxis(1)eaxis(2)## more labels than default:op <- par(lab=c(10,5,7))plot(x, sin(x)/x, type ="l", xaxt ="n")eaxis(1)# maybe (depending on your canvas), there are too many,## in that case, maybe useplot(x, sin(x)/x, type ="l", xaxt ="n")eaxis(1, axTicks(1)[c(TRUE,FALSE)])# drop every 2nd labeleaxis(3, labels=FALSE)## ore use 'max.at' which thins as well:plot(x, sin(x)/x, type ="l", xaxt ="n")eaxis(1, max.at=6)par(op)### Answering R-help "How do I show real values on a log10 histogram", 26 Mar 2013## the data: set.seed(1); summary(x <- rlnorm(100, m =2, sdl =3))## the plot (w/o x-axis) : r <- hist(log10(x), xaxt ="n", xlab ="x [log scale]")## the nice axis: axt <- axTicks(1) eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE))## Additionally demo'ing 'sub10' options: plot(r, xaxt="n") eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE, sub10 =2))## or plot(r, xaxt="n") eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE, sub10 ="10"))## or plot(r, xaxt="n") eaxis(1, at = axt, labels = pretty10exp(10^axt, drop.1=TRUE, sub10 = c(-2,2)))