Recology, and kindly contributed to Want to share your content on R-bloggers? [This article was first published on, 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 data analysis it is often nice to look at all pairwise combinations of continuous variables in scatterplots. Up until recently, I have used the function splom in the package lattice, but ggplot2 has superior aesthetics, I think anyway.

Here a few ways to accomplish the task:

# load packages

require(lattice) require(ggplot2)

1) Using base graphics, function “pairs”

pairs(iris[1:4], pch = 21)

2) Using lattice package, function “splom”

splom(~iris[1:4])

3) Using package ggplot2, function “plotmatrix”

plotmatrix(iris[1:4])

4) a function called ggcorplot by Mike Lawrence at Dalhousie University

-get ggcorplot function at this link

ggcorplot( data = iris[1:4], var_text_size = 5, cor_text_limits = c(5,10))

5) panel.cor function using pairs, similar to ggcorplot, but using base graphics. Not sure who wrote this function, but here is where I found it.

panel.cor

A comparison of run times...

> system.time(pairs(iris[1:4])) user system elapsed 0.138 0.008 0.156 > system.time(splom(~iris[1:4])) user system elapsed 0.003 0.000 0.003 > system.time(plotmatrix(iris[1:4])) user system elapsed 0.052 0.000 0.052 > system.time(ggcorplot( + data = iris[1:4], var_text_size = 5, cor_text_limits = c(5,10))) user system elapsed 0.130 0.001 0.131 > system.time(pairs(iris[1:4], lower.panel=panel.smooth, upper.panel=panel.cor)) user system elapsed 0.170 0.011 0.200

...shows that splom is the fastest method, with the method using the panel.cor function pulling up the rear.