Skip to content

Instantly share code, notes, and snippets.

@pedroj
Created March 25, 2013 16:34
Show Gist options
  • Save pedroj/5238501 to your computer and use it in GitHub Desktop.
Save pedroj/5238501 to your computer and use it in GitHub Desktop.
panelcorr
##############################################################################
# Panel with correlations for paired variables.
# Pedro Jordano. Zahara 9 Aug 2009.
##############################################################################
data(data)
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 <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits=digits)[1]
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor))
cex <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex)
}
pairs(data[1:4], lower.panel=panel.smooth,
upper.panel=panel.cor)
par(oma=c(1,1,1,1),new=T,font=2,cex=0.5)
mtext(outer=T,"Paired plots with correlations",side=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment