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)

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:


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

aranjuezDF <- subset(,
 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):

 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) )
 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 The points are selected via mouse clicks. Clicks other than left-clicks terminate the procedure.


trellis.focus('panel', 1, 1)
idx <-, cex=0.6, col='green')

To leave a comment for the author, please follow the link and comment on their blog: Omnia sunt Communia! » R-english. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , , ,

Comments are closed.

Search R-bloggers


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)