Adds an axis to the current plot, allowing the specification of the side, position, labels, and other options.
1 2 3 4
an integer specifying which side of the plot the axis is to be drawn on. The axis is placed as follows: 1=below, 2=left, 3=above and 4=right.
the points at which tick-marks are to be drawn. Non-finite
this can either be a logical value specifying whether
(numerical) annotations are to be made at the tickmarks, or a
character or expression vector of labels to be placed at the
tickpoints. (Other objects are coerced by
a logical value specifying whether tickmarks and an axis line should be drawn.
the number of lines into the margin at which the axis line
will be drawn, if not
the coordinate at which the axis line is to be drawn:
a logical value indicating whether the axis should be drawn in the outer plot margin, rather than the standard plot margin.
font for text. Defaults to
line type for both the axis line and the tick marks.
line widths for the axis line and the tick marks. Zero or negative values will suppress the line or ticks.
colors for the axis line and the tick marks
adjustment for each tick label perpendicular to the
reading direction. For labels parallel to the axes,
other graphical parameters may also be passed as
arguments to this function, particularly,
The axis line is drawn from the lowest to the highest value of
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
xpd = NA to allow axes to extend further.
at = NULL, pretty tick mark locations are computed internally
(the same way
axTicks(side) would) from
"ylog"). Note that these
locations may change if an on-screen plot is resized (for example, if
plot.window) is set.)
labels is not specified, the numeric values supplied or
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.)
pos is set, they (rather than
par("mgp")) determine the position of the axis line and tick
marks, and the tick labels are placed
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
mex, the size and
direction of the ticks is controlled by
the appearance of the tick labels by
font.axis with orientation controlled by
srt, unlike S which uses
las if it is not). Note that
adj is not
supported and labels are always centered. See
par for details.
The numeric locations on the axis scale at which tick marks were drawn when the plot was first drawn (see ‘Details’).
This function is usually invoked for its side effect, which is to add an axis to an already existing plot.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Axis for a generic interface.
axTicks returns the axis tick locations
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.