Skip to content

Instantly share code, notes, and snippets.

@ohofmann
Created February 2, 2012 17:06
Show Gist options
  • Save ohofmann/1724594 to your computer and use it in GitHub Desktop.
Save ohofmann/1724594 to your computer and use it in GitHub Desktop.
# Plot correlation score in pairs() panel
panel.cor <- function(x, y, digits=2, prefix="", cex.cor)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r = (cor(x, y, use="pairwise"))
txt <- format(c(r, 0.123456789), digits=digits)[1]
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor)) cex <- 0.6/strwidth(txt)
text(0.5, 0.5, txt, cex=cex )
}
# Standard pairs using smoothed plots for large number of data points
pairs(data,
upper.panel=function(...) smoothScatter(..., nrpoints=0, add=TRUE),
lower.panel=panel.cor
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment