# [R] splom pairs and groups argument

GOUACHE David D.GOUACHE at arvalisinstitutduvegetal.fr
Tue Oct 2 10:49:34 CEST 2007

```Hello,

I'm trying to pull off a certain graph using splom, and can't quite get my panel functions right.
Basically, the equivalent using pairs would be something like this (using iris data set as an example):

panel.corval <- function(x, y, digits=2, prefix="", cex.cor,col,pch)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y,use="complete.obs"))
txt <- format(c(r, 0.123456789), digits=digits)
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor)) cex <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex )
}
pairs(iris[,1:4], lower.panel=panel.smooth, upper.panel=panel.corval,col=rainbow(nlevels(iris\$Species))[iris\$Species],pch=19)

My goals are:
1) to have in one panel (above or below the diagonal) the points themselves with a smoothing line over all the points and in the other the (absolute) value of the correlation coefficient, so as to get an overall idea of my correlations
2) to be able to identify points depending on levels of one or more factors (hence the groups argument that is giving me a hard time in writing a succesfull panel function)
3) I want to do this in splom as I want to build several scatterplot matrices subsetting my data over the levels of another factor...

Also, while trying to set up an example, I landed upon this behavior I couldn't quite make sense of:

panel.corval <- function(x, y, digits=2, prefix="", cex.cor)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y,use="complete.obs"))
txt <- format(c(r, 0.123456789), digits=digits)
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor)) cex <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex )
}
pairs(iris[,1:4], lower.panel=panel.smooth, upper.panel=panel.corval,col=rainbow(nlevels(iris\$Species))[iris\$Species],pch=19)

Erreur dans lower.panel(...) : unused argument(s) (col = c("#FF0000", "#FF0000", "#FF0000",

I can't understand why not specifying col and pch arguments in the function I use for upper.panel (which dosen't at all need them in this case) is a problem. It's all the more confusing that the error message says the problem is with lower.panel... If anyone has a clue as to what's happening, please tell.

R version 2.4.0 (2006-10-03)
i386-pc-mingw32

locale:
LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252

attached base packages:
 "grid"      "methods"   "stats"     "graphics"  "grDevices" "utils"
 "datasets"  "base"

other attached packages:
RColorBrewer      lattice
"0.2-3"    "0.14-17"