To draw a line through the points, from the smallest value of DisSev to the largest value of DisSev, the necessary ordering of the values can be determined using the order command and then DisSev and RelYield can be indexed by these ordered values. The first command lines provide an introduction to order and the related command rank.

# Set up a simple example vector

ex8 <-c(103,101,102)

# The order command give the order in which entries # must be drawn to put them in order from smallest to largest

order(ex8)

# First the 2nd entry must be drawn, then the 3rd, then the 1st. # In contrast, the rank command gives the rank of the entries # from smallest to largest.

rank(ex8)

# The first entry comes 3rd, the next entry comes first, and # the next entry comes second.

# Now use the order command and plot the DisSev data.

Suppose you would like to use color in your plots to make them easier to read or more attractive. Colors are easily added to plots using the col='color name' statement in the plot() command.

To find a list of all colors available for use in R graphics type colors(). Likewise, calling different numbers for pch in the plot command produces different shapes for the plotting points.

Using subscripts and superscripts in graph labels

To add subscripts to your x or y labels enclose the text in [] brackets, for example H[2]O. To superscript text use a tilde, ~, before the text and use the ^ before the part of the text to be raised, for example ~ cm^3.

Sometimes it's useful to specify the range for values represented in a graph rather than just using the default ranges produced by R. You can control the range of values on the x (horizontal) and y (vertical) axes using xlim and ylim.

Variations on the plot() function are called when it is applied to different types of objects. For example, when plot() is applied to categorical data, a boxplot is produced. When applied to the output from the linear regression function lm, plot() produces a set of four regression diagnostic plots.

R has interactive features, too. To see the ID for three points, try clicking on three points on the graph after entering the following:

identify(DisSev, RelYield, n=3)

To get the (x,y) coordinates for any four locations on the graph, try clicking any four places on the graph after entering locator(4). The coordinates will appear after all the locations have been clicked on.

You can also plot a particular function instead of just a set of variables.

More examples of graphing capabilities in R are available on the web, http://addictedtor.free.fr/graphiques/, and detailed instructions and illustrations are available in Murrell (2005).

Graphs can be saved in a PDF file (or a range of other formats) for later use and addition to documents. For example, the following command would save graphics output to the PDF file as named.

pdf(file='testplot.pdf')

Then, when output to that file is completed, the following command will turn off the ‘device’ that was moving output to the named file.

dev.off()

Using the interactive R windows, the simplest way to save a graph may be to right click on the graphics window and select the format for saving the graph from the menu. This operation depends on your operating system. Options may vary.