You can give an x,y coordinate for the upper left hand corner of the legend. There are several ways to indicate the location of the legend. Note: You can also use the grid( ) function to add reference lines. # add dashed blue verical lines at x = 1,3,5,7,9 Other graphical parameters (such as line type, color, and width) can also be specified in the abline( ) function. Reference LinesĪdd reference lines to a graph using the abline( ) function. The length of the major tick mark is retrieved from par("tck" ). tick.ratio is the size of the minor tick mark relative to the major tick mark. Nx is the number of minor tick marks to place between x-axis major tick marks. The minor.tick( ) function in the Hmiscpackage adds minor tick marks. Title("An Example of Creative Axes", xlab="X values", # 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", boxplot(tot_sp ~ hab, data = mydata, axis(1, at=seq(1, 2), labels = labels.Many high level plotting functions (plot, hist, boxplot, etc.) allow you to include axis and text options (as well as other graphical parameters). Some other scripts I have tried, none have worked. Script boxplot(tot_sp ~ hab, data = mydata, xlab= "Habitat Type", ylab = "Total # Species") This is the data and the code without trying to override the labels I have a number of other boxplots to do as well, some will have more than 2 values on the x axis. Basically I just want 'Riparian' to come first, then 'Floodplain'. I would like to be able to override the x labels from the data frame with my own labels OR decide the order of the values along the x axis. This puts them in the order I want but then the label isn't neat. In my data frame I changed the names to have an 'a' or 'b' at the beginning. I notice it automatically arranges the x groups in alphabetical order, which doesn't suit my needs. I am creating boxplots for some survey data in R using boxplot(). Sorry if this is very basic, but I am quite new to this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |