[R] Splom custom superpanels

Jonathan Williams williams222 at llnl.gov
Wed Aug 1 19:47:17 CEST 2007


I thought one nice addition to a splom figure would be to have the 
scatterplots in the upper triangle and a color-coordinated 
correlation matrix on the bottom.  So I tried my hand at customizing 
panel.pairs(), and was rebuffed.  Many times.  Four hours of 
fruitless debugging later, I turn to you for help:

panel.pairs(z=teststatfull[,6:12], pscales=0,
	panel.subscripts=FALSE, subscripts=,
	upper.panel=lattice.getOption("panel.splom"),
	lower.panel=function(x1=panel.args$x, y1=panel.args$y,
		panel.args=trellis.panelArgs(), subscripts=1:dim(teststatfull)[1],...){
			panel.fill(col=brewer.pal(9,"RdBu")[round(cor(x1,y1)*4 + 5)])
			panel.text(mean(x1), mean(y1), round(cor(x1,y1),2),
			font=2)})

This code is a bit above my level; I stole some tricks from examples 
I saw elsewhere, and while it looks over-clunky, it works.  Works, at 
least, in creating the superpanel: you can try it yourself by 
replacing z with a data frame or matrix of your choice and installing 
the lattice and RColorBrewer packages.  However, when I try to insert 
this into the splom function, it all goes to pot.  R scolds me for 
either missing subscripts, improper subscripts when I try to provide 
them, or missing data in the panel function, no matter how I define 
one (or don't).  Can anyone recommend a solution or show me how to 
make my superpanel function more palatable to splom?

Thanks,

Jonathan Williams
Lawrence Livermore National Laboratory



More information about the R-help mailing list