scatterplotMatrix {car}  R Documentation 
This function provides a convenient interface to the pairs
function to produce
enhanced scatterplot matrices, including univariate displays on the diagonal and a variety of fitted lines, smoothers, variance functions, and concentration ellipsoids.
spm
is an abbreviation for scatterplotMatrix
.
scatterplotMatrix(x, ...)
## S3 method for class 'formula'
scatterplotMatrix(formula, data=NULL, subset, ...)
## Default S3 method:
scatterplotMatrix(x, smooth = TRUE,
id = FALSE, legend = TRUE, regLine = TRUE,
ellipse = FALSE, var.labels = colnames(x), diagonal = TRUE,
plot.points = TRUE, groups = NULL, by.groups = TRUE,
use = c("complete.obs", "pairwise.complete.obs"), col =
carPalette()[1], pch = 1:n.groups, cex = par("cex"),
cex.axis = par("cex.axis"), cex.labels = NULL,
cex.main = par("cex.main"), row1attop = TRUE, ...)
spm(x, ...)
x 
a data matrix or a numeric data frame. 
formula 
a onesided “model” formula, of the form

data 
for 
subset 
expression defining a subset of observations. 
smooth 
specifies a nonparametric estimate of the mean or median
function of the vertical axis variable given the
horizontal axis variable and optionally a nonparametric estimate of the spread or variance function. If

id 
controls point identification; if 
legend 
controls placement, point size, and text size of a legend if the plot is drawn by groups; if 
regLine 
controls adding a fitted regression line to each plot, or to each group of points
if 
ellipse 
controls plotting dataconcentration ellipses. If 
var.labels 
variable labels (for the diagonal of the plot). 
diagonal 
contents of the diagonal panels of the plot. If 
plot.points 
if 
groups 
a factor or other variable dividing the data into groups; groups are plotted with different colors and plotting characters. 
by.groups 
if 
use 
if 
pch 
plotting characters for points; default is the plotting characters in
order (see 
col 
colors for points; the default is 
cex 
relative size of plotted points 
cex.axis 
relative size of axis labels 
cex.labels 
relative size of labels on the diagonal 
cex.main 
relative size of the main title, if any 
row1attop 
If 
... 
arguments to pass down. 
Many arguments to scatterplotMatrix
were changed in version 3 of car, to simplify use of
this function.
The smooth
argument is usually either set to TRUE
or FALSE
to draw, or omit,
the smoother. Alternatively smooth
can be set to a list of arguments. The default behavior of
smooth=TRUE
is equivalent to smooth=list(smoother=loessLine, spread=TRUE, lty.smooth=1, lwd.smooth=1.5, lty.spread=3, lwd.spread=1)
, specifying the smoother to be used, including the spread or variance smooth,
and the line widths and types for the curves. You can also specify the colors you want to use for the mean and variance smooths with the arguments col.smooth
and col.spread
. Alternative smoothers are gamline
which uses the
gam
function from the mgcv package, and quantregLine
which uses quantile regression to
estimate the median and quartile functions using rqss
from the quantreg package. All of these
smoothers have one or more arguments described on their help pages, and these arguments can be added to the
smooth
argument; for example, smooth = list(span=1/2)
would use the default
loessLine
smoother,
include the variance smooth, and change the value of the smoothing parameter to 1/2. For loessLine
and gamLine
the variance smooth is estimated by separately
smoothing the squared positive and negative
residuals from the mean smooth, using the same type of smoother. The displayed curves are equal to
the mean smooth plus the square root of the fit to the positive squared residuals, and the mean fit minus
the square root of the smooth of the negative squared residuals. The lines therefore represent the
comnditional variabiliity at each value on the horizontal axis. Because smoothing is done separately for
positive and negative residuals, the variation shown will generally not be symmetric about the fitted mean
function. For the quantregLine
method, the center estimates the median for each value on the
horizontal axis, and the spread estimates the lower and upper quartiles of the estimated conditional
distribution for each value of the horizontal axis.
The subarguments spread
, lty.spread
and col.spread
of the smooth
argument are equivalent to the newer var
, col.var
and lty.var
, respectively, recognizing that the spread is a measuure of conditional variability.
By default the diagonal argument is used to draw kernel density estimates of the
variables by setting diagonal=TRUE
, which is equivalent to setting diagonal =
list(method="adaptiveDensity", bw=bw.nrd0, adjust=1, kernel=dnorm, na.rm=TRUE)
. The additional arguments
shown are descibed at adaptiveKernel
. The other methods avaliable, with their default
arguments, are diagonal=list(method="density", bw="nrd0", adjust=1, kernel="gaussian", na.rm=TRUE)
which uses density
for nonadaptive kernel density estimation; diagonal=list(method
="histogram", breaks="FD")
which uses hist
for drawing a histogram that ignores grouping, if present;
diagonal=list(method="boxplot")
with no additional arguments which draws (parallel) boxplots;
diagonal=list(method="qqplot")
with no additional arguments which draws a normal QQ plot; and
diagonal=list(method="oned")
with no additional arguments which draws a rug plot tilted to the
diagonal, as suggested by Richard Heiberger.
Earlier versions of scatterplotMatrix
included arguments transform
and family
to estimate power transformations using the powerTransform
function before drawing the plot. The same functionality can be achieved by calling powerTransform
directly to estimate a transformation, saving the transformed variables, and then plotting.
NULL
, returned invisibly. This function is used for its side effect: producing
a plot. If point identification is used, a vector of identified points is returned.
John Fox jfox@mcmaster.ca
Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.
pairs
, scatterplot
,
dataEllipse
, powerTransform
,
bcPower
, yjPower
, cov.trob
,
showLabels
, ScatterplotSmoothers
.
scatterplotMatrix(~ income + education + prestige  type, data=Duncan)
scatterplotMatrix(~ income + education + prestige  type, data=Duncan,
regLine=FALSE, smooth=list(span=1))
scatterplotMatrix(~ income + education + prestige,
data=Duncan, id=TRUE, smooth=list(method=gamLine))