Graphical methods

The graphics capabilities in Splus are an interactive, informative, and flexible way to look at data. In order to plot graphs in Splus it is necessary to open a graphics device:

You can open a graphics window with the (Splus) command:

> motif()
or
> trellis.device()
To exit the graphics device use:
> dev.off()
Yo need to open the graphics window before asking for the graph of something. Some basic graphics commands are:
barplot(x)
creates a bar graph.

boxplot(x)
produces side by side boxplots from a number of vectors.
contour(x)
make a contour plot and possibly return coordinates of contour lines.
coplot(x)
produces a Conditioning Plot in the current graphics device which shows how a response depends on a predictor given another predictor.
dotchart(x)
plots a dot chart from a vector.
faces(x)
represents each multivariate observation as a face.
hist(x)
creates a histogram.
pairs(x)
creates on the current graphics device a figure which contains all of the scatterplots of one variable against another.
persp(x)
creates a perspective plot given a matrix that represents heights on an evenly spaced grid. Axes and/or a box may be placed on the plot.
pie(x)
creates a pie chart from a vector of data.
plclust(x)
creates a plot of a clustering tree given a structure produced by hclust.
plot(x,y) )
creates a scatterplot.
qqnorm(x)
produces a graphical display to test the distribution of data.
qqplot(x)
produces a graphical display to test the distribution of data.
stars(x)
creates star plots from a matrix of multivariate data.
stem(x)
prints a stem-and-leaf display for the given data. The form of the display can be produced automatically, or be controlled by the user.
usa (x)
puts all or part of the United States on the current or a new plot, with or without state boundaries.
There are several options for the graphical commands: There are several commands that add to existing graphs:
abline(a, b)
draws the line y= a+ b*x.
abline(coef)
vector containing the intercept a and slope b of the line y= a+ b*x.
abline(reg)
a regression object, such as returned by lsfit. Specifically, reg$coef, if it is of length 2, will be used to define the intercept and slope of the line. If reg$coef is of length 1, it is treated as the slope of a fit through the origin. The first two elements are used if reg$coef has length greater than 2.
abline(h=a)
draws the line y=a.
abline(v=a)
draws the line x=a.
arrows(x1,y1,x2,y2)
adds arrows from (x1,y1) to (x2,y2)
axes
adds the x- and y- axes
axis(n)
adds an axis to a specified side, n-1 is the x-axis, n=2 is the y-axis.
axis(n,at=x,labels=s,pos=y,las=m)
adds an axis to side n and puts the labels s at the positions x. x and s are vectors of the same lenght. pos shifts the axis to go through the coordinate x. las=0 adds the labels parallel to the axis, las=1 always adds horizontal labels, and las=2 rotates all labels by 45 degrees.
box()
adds the aouter box.
lines(x,y)
adds lines to an existing figure
points(x,y)
adds points to an existing figure
segments(x1,y1,x2,y2)
adds segments from (x1,y1) to (x2,y2)
text(xpos,ypos,text)
adds text at the specified locations
mtext("string",side= )
adds text in the margins of the current plot
side specifies the side on which the text is to be placed
  1. bottom
  2. left (default)
  3. top
  4. right
title("title",subtitle")
adss a title and/or subtitle

title(main= , sub= , xlab= , ylab= )
adds titles and/or axis labels to the current plot
will overwrite any existing titles and/or axis labels
legend(x,y,legend= )
puts a box at the specified x,y coordinates with examples (if possible) of the lines/points/shading used in the graph identified by user-defined text
identify(x,y,labels= )
similar to legend(), identify() prints text (labels) at the specified points
locator(n= ,type= )
returns the coordinates specified interactively on a plot
default is n=500, type="n"
by changing type, points and/or lines may be added to the plot
the locator() function can be used within the function legend() or identify() instead of specifying the x and y coordinates: legend(locator(1),legend)
the point is identified by placing the cursor over the point and pressing the left mouse button
to exit locator without identifying all "n" points, press the middle mouse button
The function par() can be used to set graphical parameters which stay in effect throughout all plotting until they are reset in another call to par or by invoking a new graphic device.

> par(mfrow=c(2,3))
                       * it is possible to specify the number and
                         arrangement of graphs on a page using the
                         mfrow= option
                       * mfrow=c(2,3) allows 6 plots to appear on
                         a page (2 rows of 6 plots each)
                       * because the mfrow argument was used within
                         the par function, the set up will stay in effect 
                         for all subsequent graphs

> par(mfrow=c(1,1))    
                       * restores the normal one-graph-per-page form
                       * this could also be done by invoking a new
                         graphic device
                         > X11()
> par(mfcol=c(3,2))    
                       * the page is set up as above except that the
                         graphs are printed columnwise, mfrow prints
                         graphs row by row
The following arguments can be specified either by the par() function or within a graphics function (for temporary parameter settings which stay in effect only for the call to the function and are then reset to their previous values).

pch=
plotting character, the default is pch="*"
it is possible to specify either a character, using quotes, or a numeric value, causing Splus to use one of a set of predefined values:
   Basic symbols            Superimposed symbols        Filled in symbols

   0  square                    7  0 and 4                15  square
   1  octagon                   8  3 and 4                16  octagon
   2  triangle                  9  3 and 5                17  triangle
   3  cross                    10  1 and 3                18  diamond
   4  X                        11  2 and 6
   5  diamond                  12  0 and 3
   6  inverted triangle        13  1 and 4
                               14  0 and 2
cex=
character expansion, ie.: cex=0.5 gives half the standard character size
adj=
string justification:
oma=
a vector specifying the margins on each of the four sides of a multiple figure region:
c(bottom, left, top, right)
where the values specified are the number of lines of text
ask=
logical value
ask=T means graphical device will prompt before going to the next page/screen of output (prevents plots from being erased before they are studied)
lab=
controls number of tick intervals and length of labels
las=
type of axis labels:
0 parallel to axis
1 horizontal
2 perpendicular to axis
For a list of all the available graphical parameters, type help(par)