Graphical Parameters
The following is a list of arguments available to control the appearance of graphs.
This list is not meant to be studied, but rather to serve as a reference throughout the
section Graphical Methods II.
The following arguments can be specified within any graphical function to specify
titles, where string is the title inserted in quotes, or a character vector containing
the title:
- main="string"
- main title, above plot, in enlarged characters
- sub="string"
- sub-title for bottom of plot
- main="# of chin ups \n Females"
- for titles and sub-titles to run over more than
one line, use \n in the character string to start
a new line
The following parameters may only be used in high-level graphical functions (those
that set up coordinate systems, e.g., plot, qqplot).
- xlab="string", ylab="string"
- labels for the x an y axes
- axes=
- logical flag specifying axes=F forces Splus to omit drawing the axes
- xlim=, ylim=
- vectors giving the min and max values for the x and y axes
- Splus may extend the axes further to produce pretty tick labels
- log=
- specifies the axes to be logarithmic (ie.: log="xy")
- type=
- type of plot:
- "p" points
- "l" lines
- "b" both
- "o" both - overstruck
- "h" high density
- "n" null (sets up the axes to be filled in later)
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
- lty=
- line type: a value of 1 gives solid lines, values of 2,3...
will select a non-solid line type
- lwd=
- line width: the default value is 1. Increasing values produce
thicker lines
- col=
- numeric color specification (default is 1)
- adj=
- string justification:
- 0 left justify
- 1 right justify
- 0.5 centre
- or any other fraction
- 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
- x= number of tick intervals on x axis
(default = 5)
- y= number of tick intervals on y axis
(default = 5)
- llen= length of labels on both axes
(default = 7)
- eg.: lab=c(x=6, y=4, llen=9)
- 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)
Other Useful FUnctions
The arguments main= and sub= cannot be used from within these functions with
the exception of title()
- points(x,y,pch= )
- the function points() allows you to add variables to the
current plot
- lines(x,y,lty= )
- the function lines() allows you to add lines to the current
plot
- abline
- adds a line to a plot
- arguments can be specified as:
- (a,b) where a = intercept and b = slope
- (coef) vector containing the intercept a and slope b
- (reg) a regression object
- (h= ) vector of y-coordinates for horizontal lines
- (v= ) vector of x-coordinates for vertical lines
- 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
- title(main= , sub= , xlab= , ylab= )
- adds titles and/or axis labels to the current plot
- will overwrite any existing titles and/or axis labels
- segments(x1,y1,x2,y2)
- adds a line segment with endpoints (x1,y1) and (x2,y2) to
the current plot
- arrows(x1,y1,x2,y2)
- adds an arrow to the current plot
- for a description of optional arguments, type help(segments)
- text(x,y,labels)
- adds text to the current plot
- the coordinates can be given by two arguments (x and y) or
by a single argument x which is a univariate time series,
a complex vector, a matrix with 2 columns, or a list
containing components named x and y
- mtext("string",side= )
- adds text in the margins of the current plot
- side specifies the side on which the text is to be placed
- bottom
- left (default)
- top
- right
- other options are available for this function, use help(mtext)
- axis
- adds an axis to the current plot
- box
- surrounds the current plot with a box
Further Reading
Richard A. Becker, John M. Chambers, Allan R. Wilks, The New S Language.
A Programming Environmnent for Data Analysis and Graphics, Wadsworth &
Brooks/Cole Advanced Books & Software, Pacific Grove, California, 1988,
Chapter 10.