axis(side, at = NULL, labels = TRUE, tick = TRUE, line = NA,
pos = NA, outer = FALSE, font = NA, lty = "solid",
lwd = 1, lwd.ticks = lwd, col = NULL, col.ticks = NULL,
hadj = NA, padj = NA, …)
NaN
or NA
) values are omitted. By default
(when NULL
) tickmark locations are computed, see
‘Details’ below.as.graphicsAnnot
.)
If this is not logical, at
should also be supplied and of the
same length. If labels
is of length zero after coercion,
it has the same effect as supplying TRUE
.NA
.NA
this overrides the value of line
.par("font")
.col = NULL
means to use par("fg")
,
possibly specified inline, and col.ticks = NULL
means to use
whatever color col
resolved to.par("adj")
) for all labels
parallel (‘horizontal’) to the reading direction. If
this is not a finite value, the default is used (centring for
strings parallel to the axis, justification of the end nearest the
axis otherwise).padj = 0
means right or top alignment, and padj = 1
means left or bottom
alignment. This can be a vector given a value for each string, and
will be recycled as necessary. If padj
is not a finite value (the default), the value of
par("las")
determines the adjustment. For strings plotted
perpendicular to the axis the default is to centre the string.
cex.axis
,
col.axis
and font.axis
for axis annotation, mgp
and xaxp
or yaxp
for positioning, tck
or
tcl
for tick mark length and direction, las
for
vertical/horizontal label orientation, or fg
instead of
col
, and xpd
for clipping. See par
on these. Parameters xaxt
(sides 1 and 3) and yaxt
(sides 2 and
4) control if the axis is plotted at all.
Note that lab
will partial match to argument
labels
unless the latter is also supplied. (Since the
default axes have already been set up by plot.window
,
lab
will not be acted on by axis
.)
at
, but will be clipped at the plot region. By default, only
ticks which are drawn from points within the plot region (up to a
tolerance for rounding error) are plotted, but the ticks and their
labels may well extend outside the plot region. Use xpd = TRUE
or xpd = NA
to allow axes to extend further. When at = NULL
, pretty tick mark locations are computed internally
(the same way axTicks(side)
would) from
par("xaxp")
or "yaxp"
and
par("xlog")
(or "ylog"
). Note that these
locations may change if an on-screen plot is resized (for example, if
the plot
argument asp
(see plot.window
) is set.) If labels
is not specified, the numeric values supplied or
calculated for at
are converted to character strings as if they
were a numeric vector printed by print.default(digits = 7)
. The code tries hard not to draw overlapping tick labels, and so will
omit labels where they would abut or overlap previously drawn labels.
This can result in, for example, every other tick being labelled.
(The ticks are drawn left to right or bottom to top, and space at
least the size of an ‘m’ is left between labels.) If either line
or pos
is set, they (rather than
par("mgp")[3]
) determine the position of the axis line and tick
marks, and the tick labels are placed par("mgp")[2]
further
lines into (or towards for pos
) the margin. Several of the graphics parameters affect the way axes are drawn. The
vertical (for sides 1 and 3) positions of the axis and the tick labels
are controlled by mgp[2:3]
and mex
, the size and
direction of the ticks is controlled by tck
and tcl
and
the appearance of the tick labels by cex.axis
, col.axis
and font.axis
with orientation controlled by las
(but
not srt
, unlike S which uses srt
if at
is
supplied and las
if it is not). Note that adj
is not
supported and labels are always centered. See par
for details.Axis
for a generic interface. axTicks
returns the axis tick locations
corresponding to at = NULL
; pretty
is more flexible
for computing pretty tick coordinates and does not depend on
(nor adapt to) the coordinate system in use. Several graphics parameters affecting the appearance are documented
in par
.require(stats) # for rnorm
plot(1:4, rnorm(4), axes = FALSE)
axis(1, 1:4, LETTERS[1:4])
axis(2)
box() #- to make it look "as usual"
plot(1:7, rnorm(7), main = "axis() examples",
type = "s", xaxt = "n", frame = FALSE, col = "red")
axis(1, 1:7, LETTERS[1:7], col.axis = "blue")
# unusual options:
axis(4, col = "violet", col.axis = "dark violet", lwd = 2)
axis(3, col = "gold", lty = 2, lwd = 0.5)
# one way to have a custom x axis
plot(1:10, xaxt = "n")
axis(1, xaxp = c(2, 9, 7))
Run the code above in your browser using DataLab