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

William Revelle lists at revelle.net
Mon Oct 4 01:29:10 CEST 2010


Dear ashz,

Unfortunately, much of you want is not possible with the current 
implementation of pairs.panels.

Since pairs.panels is adapted from the help file of pairs, you might 
try pairs and then add in the panel functions that do what you want.

That the lm option does it what it does met a need of mine for a demo 
of the difference of regression slopes of X on Y versus Y on X.  Your 
request is very reasonable and I will implement it in the next 
revision.

To get the pairwise complete rather than pairwise, you can preprocess 
your data file with na.omit

e.g.,  cfc <- na.omit(cfcap[8:11])
pairs.panesl(cfc)


At 1:37 PM -0700 10/3/10, ashz wrote:
>Hi,
>
>I used the pairs.panels() in pkg:psych and it is helpful. It saves time.
>
>but if I use this line:
>pairs.panels(cfcap[8:11],  scale = FALSE, lm=TRUE,ellipses=TRUE, digits = 2
>)
>
>The results are:
>- The upper.panel does not show the pearson r but the lm data. Furthermore,
>can I use the pairwise.complete.obs method for the upper.panel. Can it be
>fixed?



>- Can I remove the histograms?

Not as a call, but you change pairs.panels to draw just the densities 
by substituting

"panel.hist.density" <-
function(x,...) {
  usr <- par("usr"); on.exit(par(usr))
    par(usr = c(usr[1:2], 0, 1.5) )
     h <- hist(x, plot = FALSE)
     breaks <- h$breaks; nB <- length(breaks)
   y <- h$counts; y <- y/max(y)
   #rect(breaks[-nB], 0, breaks[-1], y,col=hist.col)         #  <--- 
comment this line out
   tryd <- try( d <- density(x,na.rm=TRUE,bw="nrd",adjust=1.2),silent=TRUE)
   if(class(tryd) != "try-error") {

      d$y <- d$y/max(d$y)
    lines(d)}
}

in place of the current panel.hist.density function.



>- Can I control the eliipse alpha?

Not yet.   Good idea.


Your requests are all very reasonable and will be added to my wish 
list of additions to pairs.panels.  This will not happen for several 
weeks, however.


Bill

>
>Thanks a lot.
>
>--
>View this message in context: 
>http://r.789695.n4.nabble.com/Scatterplot-matrix-Pearson-linear-correlation-and-Density-Ellipse-tp2763552p2953521.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list