Michael Hopkins
2006-Jun-24 09:47 UTC
[R] Overlaying 2D kernel density plots on scatterplot matrix
Hi all We are pretty new to R here and trying to achieve something that we believe is possible but it?s not easy to work out how to do it. We are producing scatterplot matrices for e.g. 10 variables. What we would like to do is superimpose 2D kernel density estimators on top of each plot so that we end up with a scatterplot matrix of 2D kernel density (contour) plots. The kernel density plots don?t have to be very sophisticated i.e. default settings and greyscale are fine ? we can work on details later. What has stumped us so far is how you ?attach? the kernel density results to the scatterplot results and then overlay them. Any ideas, links or code gratefully received. TIA and please CC answers here if possible Michael
Karl Ove Hufthammer
2006-Jun-26 17:57 UTC
[R] Overlaying 2D kernel density plots on scatterplot matrix
Michael Hopkins skreiv:> The kernel density plots don?t have to be very sophisticated i.e. > default settings and greyscale are fine ? we can work on details > later.??What?has stumped us so far is how you ?attach? the kernel > density results to the scatterplot results and then overlay them. > > Any ideas, links or code gratefully received.Here?s my suggestion?: library(lattice) library(MASS) splom(~iris[1:4], panel=function(x,y) { xy=kde2d(x,y) xy.tr=con2tr(xy) panel.contourplot(xy.tr$x, xy.tr$y, xy.tr$z, subscripts=seq(nrow(xy.tr)), contour=TRUE, region=FALSE) panel.xyplot(x,y) } ) ? Which is basically Richard M. Heiberger?s solution to a similar query I had on this list earlier about a month ago: http://tolstoy.newcastle.edu.au/R/help/06/05/27184.html -- Karl Ove Hufthammer