S-Plus creates three kinds of graphics, depending on how you count. Traditional or command-line graphics come from the command-line. New style or Axum graphics come from the GUI, and Trellis (tm) graphics can be generated either way. The reason that S-Plus has the first two is originally historical but each provides some advantages. The third represents a different approach to graphics that's worth learning about.

Graphics Devices

S-Plus has a number of different types of graphics devices, but you generally won't care. The usual graphics device is the graphsheet. That gets started automatically by the plotting command and carries a name like "GS1" (if you create the graph from the GUI) or "GSD1" (from the command line). If you issue another plot command, it will generally clear your device. To start a second device simultaneously with the first, use the graphsheet() command explicitly. You can give your picture a meaningful title and set a host of other options there. The dev.set(), dev.cur() and related commands let you manage your windows from within a function. If you end up with a million windows, will close all of them.

S-Plus has a few other devices that might be useful: postscript() Postscript graphics, wmf.graph() and pdf.graph() for producing Postscript files, Windows Metafiles and PDF documents. The java.graph() device produces "graphlets," which are interactive graphics for Web pages (see the User's Manual). Finally you shouldn't use one of these devices Trellis graphics (below); use trellis.device() instead. This performs some special set-up routines for Trellis graphs: you can specify whether the ultimate output will be to graphsheet, wmf, or pdf devices.

Command-line Graphics

Command-line Graphics Are Editable If...

Until recent versions of S-Plus, traditional graphics (produced at the command line) weren't editable. Therefore a good approach was to create them with a function, editing the function until you got everything exactly as you wanted it. This is still a good approach if you need to produce a specific sort of graph many times. Non-editable graphics are drawn a bit faster that the editable kind, so they're useful when you have very big data sets.

In S-Plus 6, command-line graphics can be edited if the "editable graphics" button on the command-line toolbar is depressed. Editing graphics in S-Plus is done as in Excel: click on an axis to change it, click on the data itself to change the plotting character, and so on.

The plot() Command

The basic command-line command for producing a scatter plot or line graph is plot(). This function takes a number of options that are detailed in the help for par(). The ones you need to know right away are col= to set colors, lty= to set line types (dotted and dashed), lwd= to set line widths, pch= to set the character type, type= to pick points (type = "p"), lines ("l"), or both ("b"), and cex= to set the "character expansion" (font size). Also important are xlab= and ylab= to set the labels, xlim= and ylim= to set the limits of the axes, and main= to put a title on the plot. See help (par) for details on these and lots of other options.

The mtext() function, to add a sub-title, is also useful here.

Other commands that are useful are boxplot(), barplot(), hist() and pie().

You can add stuff to a plot with the text() and arrows() commands. text() is vectorized, so it supplements points() as a good way to add plotting symbols that are text. Often you'll want to find the co-ordinates of a particular spot on the graph so you can place an arrow or some textual annotation. The locator() function will do the trick.

Special Commands Worth Knowing

Here are a few more tips:

plot() as a generic function

Some objects have particular plotting needs. For those objects there may be special plotting methods already written. For example, if your object mylm has a class of lm, then when you issue the plot(mylm) command, S-Plus knows that the particular plot function it should call is the plot.lm() function. plot() is a generic function with methods for lots of different classes. See classes and methods for more information.

GUI Graphics

There are lots of types of graph available on the 2D palette and under the Graph menu. GUI graphics are generally editable, either directly or through the Object Explorer. One of the great things about the GUI is that it's easy to go straight from a data window to a graph: just click your columns (X, then Y) and plot. Customizing is easy, too. The only real disadvantages of GUI graphics are that it can be hard to create hundreds of them, and that you can't create new types.

Saving The Commands Used To Create A GUI Graphic

Sometimes it takes while to get a graphic to exactly where you want it. Once you've done that you can save it by opening a new script window, copying the graphic window and pasting it into the script window. The code it produces is very complicated, but it works most of the time. (Plotting separate vectors, rather than columns in a data frame, seems to fail.) You can also drag and drop the graphic into a script window but this hardly ever works for me.

Trellis(tm) (Lattice) Graphics

Trellis is a trademark for a way of displaying multiple plots. As a general name let us use the word "lattice" to describe this approach. In a lattice we see a set of plots, each displaying a relationship between two or more variables. The different panels of the graph condition the pictures on the values of yet another variable. S-Plus takes care of a lot of details here: all the axes are the same, for example. Trellis graphs can be produced at the command line, but it's easier to produce them from the GUI. Do one of these:

Saving and Exporting Graphics to Word

When you "save" a graph it gets stored in S-Plus's own ".sgr" format. The next time you start S-Plus you can open such a graph back up and continue editing it. You don't need to save or export a graphic to insert it into Word: you can just copy and paste it and that works fine. However I don't recommend editing inside Word. For one thing your vertical axis label will be rotated.

Personally I'm in the habit of saving my pictures on disk. A good format for this is WMF is you're using Office. (EPS with WMF header is a good choice if you're using LaTex.) Then in Word use Import | Picture | From File to get the picture into your document and change the picture's properties as necessary.

Making PowerPoint Presentations From Your S-Plus Graphics

S-Plus has a cool "Make PowerPoint Presentation" that turns your graphs into PowerPoint instantly. Just press the button and off you go.

Return to S-Plus docs