Add an Axis to the Current Plot

DESCRIPTION:
Adds an axis to the current plot. The side, positioning of tick marks, labels and other options can be specified.

USAGE:
axis(side, at=<<see below>>, labels=T, ticks=T, distn=NULL, line=0,
      pos=<<see below>>, outer=F)

REQUIRED ARGUMENTS:
side:
a number representing the side of the plot for the axis (1 for bottom, 2 for left, 3 for top, and 4 for right).

OPTIONAL ARGUMENTS:
at:
vector of positions at which the ticks and tick labels will be plotted. If side is 1 or 3, at represents x-coordinates. If side is 2 or 4, at represents y-coordinates. If at is omitted, the current axis (as specified by the xaxp or yaxp parameters, see par) will be plotted.
labels:
if labels is logical, it specifies whether or not to plot tick labels. Otherwise, labels must be the same length as at, and label[i] is plotted at coordinate at[i].
ticks:
if TRUE, tick marks and the axis line will be plotted.
distn:
character string describing the distribution used for transforming the axis labels. The only choice is distn="normal", in which case values of at are assumed to be probability levels, and the labels are actually plotted at qnorm(at). This also implies a reasonable default set of values for the at argument. By default the values in at are used as the labels.
line:
distance from the plot (measured out from the plot in units of standard-sized character heights) at which the axis line will be plotted. Tick labels will be plotted relative to this position using the graphical parameter mgp).
pos:
x- or y-coordinate position at which the axis line should be plotted. Labels will be on the side of the axis specified by side. If pos is omitted, argument line controls positioning of the axis.
outer:
if TRUE, the axis will be drawn in the outer margin rather than the standard plot margin.

Graphical parameters may also be supplied as arguments to this function (see par). However, arguments to title such as xlab and ylab are not allowed. For string rotation use the las graphical parameter: 0 = always parallel to the axis (the default), 1 = always horizontal to the axis, 2 = always perpendicular to the axis. The srt graphical parameter is ignored.


DETAILS:

If at is not given, then axis uses the the following procedure to place the tick mark labels. axis rotates the tick mark labels to be parallel to the axes if the graphical parameter las is 0, horizontal if las is 1, and perpendicular to the axes if las is 2. (This overrides the current value of the graphical parameter srt.) The tick mark labels are centered at the tick mark if they are parallel to the axis and right or left justified if they are perpendicular to the axis and to the left or right of it, respectively. (This overrides the current value of the graphical parameter adj.)

If at is used to specify where to place the tick mark labels, then axis uses srt to specify how to rotate the labels (ignoring the las parameter and side argument) and it uses the adj parameter to specify the string adjustment (ignoring the side argument).


SIDE EFFECTS:
An axis is added to the current plot.

SEE ALSO:
title , mtext , par .

EXAMPLES:
axis(3)  # add axis on top
axis(4, label=F)  # tick marks only on right

qqnorm(data) axis(3, distn="normal") # add normal probability axis at top

qqnorm(data, xaxt="n") # normal prob plot, no x axis labels probs <- c(.01, .05, .1, .9, .95, .99) axis(1, distn="norm", at=probs, lab=paste(probs*100, "%")) # add user-defined probability axis

plot(x, y, axes=F) # scatter plot with no box or axes axis(1, pos=0); axis(2, pos=0) # coordinate axes through origin

fahrenheit <- c(25, 28, 37, 49, 59, 69, 73, 71, 63, 52, 42, 29) plot(fahrenheit, axes=F, pch=12, xlab="", ylab="Fahrenheit", sub="Monthly Mean Temperatures for Hartford, Conn.") axis(2) axis(1, at=1:12, labels=month.abb) celsius <- pretty((range(fahrenheit)-32)*5/9) axis(side=4, at=celsius*9/5+32, lab=celsius, srt=90) # celsius at right mtext(side=4, line=4, "Celsius") box()