next up previous
Next: Multiple Plots per Page Up: Producing Graphics in S-PLUS Previous: Adding Text

Plotting Points

Another way to create or embellish a plot is by adding points. Suppose we were interested in returning to the students vs. expenditures plot (where there did not appear to be any clear relationship) and breaking the data down by region. To plot the points from the West (and label them with W's instead of *'s) we could use:

> plot(Y69[Region=="WEST"], SE70[Region=="WEST"], pch="W")
(The pch= field tells S-PLUS what character to use for the points.) This plot is OK for displaying the West points, but if we tried to add points from any other region, some might be outside the range of this graph. This happens because plot chose a range for the axes to fit the West points as well as possible, without any consideration for the other points. It is better to first create an empty plot which fits the full data, and then fill in the West points.

> plot(Y69, SE70, type="n")
> points(Y69[Region=="WEST"], SE70[Region=="WEST"], pch="W")
points 1

Now points from any other section can be added to this graph and they will fit. For instance, the Northeast:

> points(Y69[Region=="NOREAST"], SE70[Region=="NOREAST"], pch="N")
points #2

This shows that the Northeastern states had fewer students per capita, but about the same range of expenditures as the non-Alaska Western states.


next up previous
Next: Multiple Plots per Page Up: Producing Graphics in S-PLUS Previous: Adding Text
Brian Junker 2002-08-26