Learn R Programming

sfsmisc (version 1.0-15)

eaxis: Extended / Engineering Axis for Graphics

Description

An extended axis() function which labels more prettily, in particular for log-scale axes.

It makes use of plotmath expressions of the form $k \times 10^k$ for labeling a log-scaled axis and when otherwise exponentional formatting would be used.

Usage

eaxis(side, at = axTicks(side, log=log), labels = NULL, log = NULL,
      f.smalltcl = 3/5, at.small = NULL, small.mult = NULL,
      outer.at = TRUE, drop.1 = TRUE, las = 1, max.at = Inf, ...)

Arguments

side
integer in 1:4, specifying side of axis.
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 = T
log
logical or NULL specifying if log-scale should be used; the default depends on the current plot's axis.
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
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().
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.
las, ...
arguments passed to (the first) axis call. Note that the default las = 1 differs from axis's default las = 0.

See Also

axis, axTicks, axTexpr, pretty10exp.

Examples

Run this code
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)

## 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)

x <- seq(-1, 1, length = 1000)
plot(x, sin(x)/x, type = "l", xaxt = "n")
eaxis(1)

x <- x/1000
plot(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 use
plot(x, sin(x)/x, type = "l", xaxt = "n")
eaxis(1, axTicks(1)[c(TRUE,FALSE)]) # drop every 2nd label
eaxis(3, labels=FALSE)
par(op)

Run the code above in your browser using DataLab