How to display scatter plot matrices with R and lattice

[This article was first published on Omnia sunt Communia! » R-english, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In lattice, there is a function called splom for the display of scatter plot matrices. For large datasets, the panel.hexbinplot from the hexbin package is a better option than the default panel.

As an example, let’s use some meteorological data from MAPA-SIAR:

library(solaR)
library(hexbin)

aranjuez <- readMAPA(prov=28, est=3, start='01/01/2004', end='31/12/2010')

aranjuezDF <- subset(as.data.frame(getData(aranjuez)),
 select=c('TempMedia', 'TempMax', 'TempMin',
 'HumedadMedia', 'DirViento', 'EtPMon',
 'Precipitacion', 'G0'))

Now we can use splom with panel.hexbinplot and panel.loess. Besides, I have included some changes to diag.panel in order to show the univariate density of each variable (adapted from here):

splom(aranjuezDF,
 panel=panel.hexbinplot,
 diag.panel = function(x, ...){
 yrng <- current.panel.limits()$ylim
 d <- density(x, na.rm=TRUE)
 d$y <- with(d, yrng[1] + 0.95 * diff(yrng) * y / max(y) )
 panel.lines(d)
 diag.panel.splom(x, ...)
 },
 lower.panel = function(x, y, ...){
 panel.hexbinplot(x, y, ...)
 panel.loess(x, y, ..., col = 'red')
 },
 pscale=0, varname.cex=0.7
 )

Finally, it is interesting to identify some points. This task is easy with panel.link.splom. The points are selected via mouse clicks. Clicks other than left-clicks terminate the procedure.

 

trellis.focus('panel', 1, 1)
idx <- panel.link.splom(pch=13, cex=0.6, col='green')
aranjuezDF[idx,]

To leave a comment for the author, please follow the link and comment on their blog: Omnia sunt Communia! » R-english.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)