[R] Lattice: splom plots for different factors with correlation in lower.panel

From: Tom Porteus <porteus_at_zoology.ubc.ca>
Date: Mon, 09 May 2011 15:00:27 -0700 (PDT)


Hello list,
I am looking to create a figure for my dataset using splom, where there is a splom subplot for each level of a factor within, for example, a 2x2 layout. For each subplot, I wish to put the r-value between each variable pair in the lower panel. The code I have thus far is below, using the iris dataset so that it is reproducible. This almost does what I want, but for some reason overlays the r-values for each level in each subplot.

I think the problem is something to do with the lower.panel function call within my custom function, but I am not a huge whizz using lattice and can't figure out what it is. If I put the panel.text call in the lower.panel function, it only causes a similar problem. Apologies if there is something obvious I have missed, I hope there is someone out there who can help me!

var.cor <- list()
for(i in 1:3){

	var.cor[[i]] <- abs(cor(subset(iris[1:4], iris$Species ==
levels(iris$Species)[i])))	#calculate variable correlation for each species
	var.cor[[i]] <- data.frame(values = as.vector(var.cor[[i]]), row =
as.vector(row(var.cor[[i]])), col = as.vector(col(var.cor[[i]])))
	var.cor[[i]] <- subset(var.cor[[i]], col<row)	#create data frame with value
and row & col indexes for values with each panel
}

panel.pairs.cor <- function(z, ...){
	panel.pairs(z, upper.panel=panel.splom, lower.panel=function(){}, ...)
	for(i in 1:3){
		panel.text(x=var.cor[[i]]$row, y=var.cor[[i]]$col,
labels=round(var.cor[[i]]$values, 2))
	}	

}

splom(~iris[1:4]|iris$Species, layout=c(2,2), pscales=0, col="black", xlab="", ylab="", as.table=TRUE, superpanel=panel.pairs.cor)

Many thanks,
Tom

--
View this message in context: http://r.789695.n4.nabble.com/Lattice-splom-plots-for-different-factors-with-correlation-in-lower-panel-tp3510452p3510452.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 10 May 2011 - 02:55:05 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 10 May 2011 - 03:00:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive