

# add a main title and bottom and left axis labels # draw an axis on the right, with smaller text and ticksĬol.axis="blue", las=2, cex.axis=0.7, tck=-.01)

# create extra margin room on the right for an axis xaxt="n" and yaxt="n" suppress the x and y axis respectively.

The option axes=FALSE suppresses both x and y axes. If you are going to create a custom axis, you should suppress the axis automatically generated by your high level plotting function. Length of tick mark as fraction of plotting region (negative number is outside graph, positive number is inside, 0 suppresses ticks, 1 creates gridlines) default is -0.01 Labels are parallel (=0) or perpendicular(=2) to axis (i.e., the value on the other axis where it crosses) The coordinate at which the axis line is to be drawn. )Īn integer indicating the side of the graph to draw the axis (1=bottom, 2=left, 3=top, 4=right)Ī numeric vector indicating where tic marks should be drawnĪ character vector of labels to be placed at the tickmarks You can create custom axes using the axis( ) function.Īxis( side, at=, labels=, pos=, lty=, col=, las=, tck=. See help(plotmath) for details and examples. You can add mathematically formulas to a graph using TEX-like rules. Xlab="Weight", ylab="Mileage", pch=18, col="blue") The x, y, and label vectors should all be the same length. Specify location as a set of x, y coordinates and specify the text to place as a vector of labels. You can use the text( ) function (see above) for labeling point as well as for adding other text annotations. Other common options are cex, col, and font (for size, color, and font style respectively). you can also specify adj=0 for left/bottom alignment or adj=1 for top/right alignment. you can specify line= to indicate the line in the margin starting with 0 and moving out. If you specify pos, you can specify offset= in percent of character width. Alternatively, the text can be placed interactively via mouse by specifying location as locator(1). (To practice adding text to plots in R, try this interactive exercise.) text( ) places text within the graph while mtext( ) places text in one of the four margins. Text can be added to graphs using the text( ) and mtext( ) functions. Many other graphical parameters (such as text size, font, rotation, and color) can also be specified in the title( ) function. Xlab=" x-axis label", ylab=" y-axis label") Title(main=" main title", sub=" sub-title", Use the title( ) function to add labels to a plot. Xlim=c( xmin, xmax), ylim=c( ymin, ymax))įor finer control or for modularization, you can use the functions described below. Xlab=" X-axis label", ylab=" y-axix label", Plot( x, y, main=" title", sub=" subtitle", Many high level plotting functions (plot, hist, boxplot, etc.) allow you to include axis and text options (as well as other graphical parameters).
