contour
and persp
methods that will work with any lm
object
involving two or more numerical predictors.## S3 method for class 'lm':
contour(x, form, at, bounds, zlim, xlabs, hook,
plot.it=TRUE, atpos = 1, image=FALSE, img.col=terrain.colors(50), ...)
## S3 method for class 'lm':
image(x, form, at, bounds, zlim, xlabs, hook, atpos = 1, ...)
## S3 method for class 'lm':
persp(x, form, at, bounds, zlim, zlab, xlabs, col = "white",
contours = NULL, hook, atpos = 3, theta = -25, phi = 20, r = 4,
border = NULL, box = TRUE, ticktype = "detailed", ...)
lm
object.x1
, x2
, and x3
, the contour plot of x2
versus x1
would be
based zlim
setting passed to image
.
If not provided, the range of values across all plotted surfaces is used.pre.plot
and post.plot
.
May be used to add annotations or to re-route the graphs to separate files (see Details).at
values are displayed. A value of 1 (or 2) displays it as part of the x (or y) axis label.
A value of 3 displays it as a subtitle below the plot. A value of 0 suppresses it.
Any other nonzero vTRUE
if you want an image plot overlaid by contours.image=TRUE
.TRUE
, no plot is produced, just the return value.NULL
, specifications for added contour lines in perspective plot.persp
(different defaults).persp
(different default).persp
.persp
(different default).list
containing information that is plotted.
Each list item is itself a list
with the following components:atpos
is 0)zlim
valuespersp
only) The 3D transformation for trans3d
form
may be a single formula or a list of formulas. A simple formula like
x2 ~ x1
will produce a contour plot of the fitted regression surface
for combinations of x2
(vertical axis) and x1
(horizontal axis).
A list of several such simple formulas will produce a contour plot for each formula.
A two-sided formula produces contour plots for each left-hand variable versus each
right-hand variable (except when they are the same); for example,
x1+x3 ~ x2+x3
is equivalent to
list(x1~x2, x3~x2, x1~x3)
.
A one-sided formula produces contour plots for each pair of variables. For example,
~ x1+x2+x3
is equivalent to
list(x2~x1, x3~x1, x3~x2)
.
For any variables not in the bounds
argument, a grid of 26 equally-spaced
values in the observed range of that variable is used. If you specify a vector of
length 2, it is interpreted as the desired range for that variable and a grid of 26
equally-spaced points is generated. If it is a vector of length 3, the first two elements are used
as the range, and the third as the number of grid points.
If it is a vector of length 4 or more, those
values are used directly as the grid values.
By default, the predictor axes are labeled using the variable names in form
,
unless x
is an rsm
object, in which case the variable-coding formulas,
if present, are used to generate axis labels.
These labels are replaced by the entries in xlabs
if provided. One must be careful using this
to make sure that the names are mapped correctly. The entries in xlabs
should match the respective unique variable names in form
, after sorting them in
(case-insensitive) alphabetical order. Note that if form
is changed, it may also
be necessary to change xlabs
.
In persp
, contour lines may be added via the contours
argument. It may be a boolean or character value, or a list
.
If boolean and TRUE
, default black contour lines are added to the bottom surface of the box. Character values of "top"
, "bottom"
add black contour lines to the specified surface of the box. contours = "colors"
puts contour lines on the bottom using the same colors as those
at the same height on the surface. Other character values of contours
are taken to be the desired color of the contour lines, plotted at the bottom.
If contours
is a list
, its elements (all are optional) are used as follows:
[object Object],[object Object],[object Object]
Since these functions often produce several plots, the hook
argument is provided if special setups or annotations are needed for each plot. It
should be a list that defines one or both of the functions pre.plot
and post.plot
. Both of these functions have one argument, the character
vector labs
for that plot (see Value documentation).
Additional examples and discussion of these plotting functions is available via vignette("rsm-plots")
.contour
library (rsm)
heli.rsm = rsm (ave ~ block + SO(x1, x2, x3, x4), data = heli)
# Plain contour plots
par (mfrow = c (2,3))
contour (heli.rsm, ~x1+x2+x3+x4, at=canonical(heli.rsm)$xs)
# Same but with image overlay, slices at origin and block 2,
# and no slice labeling
contour (heli.rsm, ~x1+x2+x3+x4, at=list(block="2"), atpos=0, image=TRUE)
# Default perspective views
persp (heli.rsm, ~x1+x2+x3+x4, at=canonical(heli.rsm)$xs)
# Same plots, souped-up with facet coloring and axis labeling
persp (heli.rsm, ~x1+x2+x3+x4, contours="col", col=rainbow(40), at=canonical(heli.rsm)$xs,
xlabs = c("Wing area", "Wing length", "Body width", "Body length"), zlab = "Flight time")
### Hints for creating graphics files for use in publications...
# Save perspective plots in one PDF file (will be six pages long)
pdf(file = "heli-plots.pdf")
persp (heli.rsm, ~x1+x2+x3+x4, at=canonical(heli.rsm)$xs)
dev.off()
# Save perspective plots in six separate PNG files
png.hook = list()
png.hook$pre.plot = function(lab)
png(file = paste(lab[3], lab[4], ".png", sep = ""))
png.hook$post.plot = function(lab)
dev.off()
persp (heli.rsm, ~x1+x2+x3+x4, at=canonical(heli.rsm)$xs, hook = png.hook)
Run the code above in your browser using DataLab