Rev 35820 | Rev 36117 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{axis}\alias{axis}\title{Add an Axis to a Plot}\description{Adds an axis to the current plot, allowing thespecification of the side, position, labels, and other options.}\usage{axis(side, at = NULL, labels = TRUE, tick = TRUE, line = NA,pos = NA, outer = FALSE, font = NA, vfont = NULL,lty = "solid", lwd = 1, col = NULL, hadj = NA, padj = NA,\dots)}\arguments{\item{side}{an integer specifying which side of the plot the axis isto be drawn on. The axis is placed as follows: 1=below,2=left, 3=above and 4=right.}\item{at}{the points at which tick-marks are to be drawn. Non-finite(infinite, \code{NaN} or \code{NA}) values are omitted. By default,when \code{NULL}, tickmark locations are computed, see Details below.}\item{labels}{this can either be a logical value specifying whether(numerical) annotations are to be made at the tickmarks, or a vectorof character strings or expressions to be placed at the tickpoints.If this is specified as strings or expressions, \code{at} should besupplied and they should be the same length.}\item{tick}{a logical value specifying whether tickmarks should bedrawn}.\item{line}{the number of lines into the margin which the axis willbe drawn. This overrides the value of the graphical parameter\code{mgp[3]}. The relative placing of tickmarks and tick labelsis unchanged.}\item{pos}{the coordinate at which the axis line is to be drawn:this overrides the values of both \code{line} and \code{mgp[3]}.}\item{outer}{a logical value indicating whether the axis should bedrawn in the outer plot margin, rather than the standard plotmargin.}\item{font}{font for text.}\item{vfont}{vector font for text.}\item{lty, lwd}{line type, width for the axis line and the tick marks.}\item{col}{color for the axis line and the tick marks. The default\code{NULL} means to use \code{par("fg")}.}\item{hadj}{adjustment (see \code{\link{par}("adj")} for all labels\emph{parallel} (\sQuote{horizontal}) to the reading direction. Ifthis is not a finite value, the default is used (centring forstrings parallel to the axis, justification of the end nearest theaxis otherwise).}\item{padj}{adjustment for each tick label \emph{perpendicular} to thereading direction. For labels parallel to the axes, \code{padj=0}means right or top alignment, and \code{padj=1} means left or bottomalignment. This can be a vector given a value for each string, andwill be recycled as necessary.If \code{padj} is not a finite value (the default), the value of\code{par("las")} determines the adjustment. For strings plottedperpendicular to the axis the default is to centre the string.}\item{\dots}{other graphical parameters may also be passed asarguments to this function, particularly, \code{cex.axis},\code{col.axis} and \code{font.axis} for axis annotation, \code{mgp}and \code{xaxp} or \code{yaxp} for positioning, \code{tck} or\code{tcl} for tick mark length and direction, \code{las} forvertical/horizontal label orientation, or \code{fg} instead of\code{col}, see \code{\link{par}} on these.}}\value{The numeric locations on the axis scale at which tick marks were drawnwhen the plot was first drawn (see Details).This function is usually invoked for its side effect, which is to addan axis to an already existing plot.}\details{The axis line is drawn from the lowest to the highest value of\code{at}, but will be clipped at the plot region. Only ticks whichare drawn from points within the plot region (up to a tolerance forrounding error) are plotted, but the ticks and their labels may wellextend outside the plot region.When \code{at = NULL}, pretty tick mark locations are computed internally(the same way \code{\link{axTicks}(side)} would) from\code{\link{par}("xaxp")} or \code{"yaxp"} and\code{\link{par}("xlog")} (or \code{"ylog"}). Note that theselocations may change if an on-screen plot is resized (for example, if\code{plot} argument \code{\link[graphics:plot.window]{asp}} is set).Several of the graphics parameters affect the way axes are drawn. Thevertical (for sides 1 and 3) positions of the axis and the tick labelsare controlled by \code{mgp}, the size and direction of the ticks iscontrolled by \code{tck} and \code{tcl} and the appearance of the ticklabels by \code{cex.axis}, \code{col.axis} and \code{font.axis} withorientation controlled by \code{las} (but not \code{srt}, unlike Swhich uses \code{srt} if \code{at} is supplied and \code{las} if it isnot). Note that \code{adj} is not supported.See \code{\link{par}} for details.}\seealso{\code{Axis} for a generic interface.\code{\link{axTicks}} returns the axis tick locationscorresponding to \code{at=NULL}; \code{\link{pretty}} is more flexiblefor computing pretty tick coordinates and does \emph{not} depend on(nor adapt to) the coordinate system in use.Several graphics parameters affecting the appearance are documentedin \code{\link{par}}.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole.}\examples{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 axisplot(1:10, xaxt = "n")axis(1, xaxp=c(2, 9, 7))}\keyword{aplot}