[R] Scatterplot matrix - Pearson linear correlation and Density Ellipse

Peter Ehlers ehlers at ucalgary.ca
Fri Oct 1 17:03:50 CEST 2010


On 2010-09-30 15:42, ashz wrote:
>
> Hi,
>
> I have modified a known script to generate a  scatterplot matrix:
>
> panel.cor = function(x, y, digits=2, prefix="Rho=", cex.cor)
> {
>      usr = par("usr"); on.exit(par(usr))
>      par(usr = c(0, 1, 0, 1))
>      r = abs(cor(x, y, use="pairwise.complete.obs", method = "pearson"))
>      txt = format(c(r, 0.123456789), digits=digits)[1]
>      txt = paste(prefix, txt, sep="")
>      if(missing(cex.cor)) cex.cor = 0.8/strwidth(txt)
>      text(0.5, 0.5, txt, cex = cex.cor)
> }
>
> pairs(ap[8:11], lower.panel=panel.smooth, upper.panel=panel.cor)
>
> My question is how I can change the lower.panel to show both the pearson
> linear correlation and Density Ellipse?
>

Have a look at pairs.panels() in pkg:psych.

   -Peter Ehlers

> Thanks a lot.
> As Hz
>



More information about the R-help mailing list