The **car** package can condition the scatterplot matrix on a factor, and optionally include lowess and linear best fit lines, and boxplot, densities, or histograms in the principal diagonal, as well as rug plots in the margins of the cells.

`# Scatterplot Matrices from the car Package`

library(car)

scatterplot.matrix(~mpg+disp+drat+wt|cyl, data=mtcars,

main="Three Cylinder Options")

The** lattice **package provides options to condition the scatterplot matrix on a factor.

`# Scatterplot Matrices from the lattice Package`

library(lattice)

splom(mtcars[c(1,3,5,6)], groups=cyl, data=mtcars,

panel=panel.superpose,

key=list(title="Three Cylinder Options",

columns=3,

points=list(pch=super.sym$pch[1:3],

col=super.sym$col[1:3]),

text=list(c("4 Cylinder","6 Cylinder","8 Cylinder"))))

The **gclus** package provides options to rearrange the variables so that those with higher correlations are closer to the principal diagonal. It can also color code the cells to reflect the size of the correlations.

`# Scatterplot Matrices from the glus Package`

library(gclus)

dta <- mtcars[c(1,3,5,6)] # get data

dta.r <- abs(cor(dta)) # get correlations

dta.col <- dmat.color(dta.r) # get colors

# reorder variables so those with highest correlation

# are closest to the diagonal

dta.o <- order.single(dta.r)

cpairs(dta, dta.o, panel.colors=dta.col, gap=.5,

main="Variables Ordered and Colored by Correlation" )

http://www.statmethods.net/graphs/scatterplot.html