)Ī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", Notice that base R automatically produced y-axis interval values and then used the range of x-axis interval values that we specified.Many high level plotting functions (plot, hist, boxplot, etc.) allow you to include axis and text options (as well as other graphical parameters). Plot(x, y, col=' steelblue', pch= 19, xaxt=' n')
R plot rename x axis how to#
The following code shows how to modify the x-axis interval in a plot in base R using the : function: #define data Example 3: Specify Axis Intervals Using a Range of Values Notice that the only values shown along the x-axis and y-axis are the values we specified using the seq() function. The following code shows how to modify the x-axis and y-axis intervals in a plot in base R using the seq() function: #define data Example 2: Specify Axis Intervals Using a Sequence of Values Notice that the only values shown along the x-axis and y-axis are the specific values that we specified. The following code shows how to modify the x-axis and y-axis intervals in a plot in base R using the c() function: #define data Example 1: Specify Axis Intervals Using Individual Values The following examples show how to use this syntax in practice. You can use the following basic syntax to change axis intervals on a plot in base R: #create plot with no axis intervals