[R] Axis scaling for pairs plots

David Stevens david.stevens at usu.edu
Wed Jul 10 06:36:26 CEST 2013


I have a question concerning axis scaling for pairs plots. My data set 
has columns with differing units and I want a pairs plot with scatter+an 
lm line+a correlation confidence ellipse for each lower panel. The 95% 
confidence ellipse (using the ellipse package+a polygon) gives me an 
ellipse that can extend well beyond the axis limits. At times I'll want 
the entire ellipse in the panel with the points range squeezed 
accordingly. The panel.ellipse function I wrote looks like this:

panel.ellipse <- function (x, y, col = par("col"), bg = NA, pch = 
par("pch"),
     cex = 1, ...)
{
     points(x, y, pch = pch, col = col, bg = bg, cex = cex)
     ok <- is.finite(x) & is.finite(y)
     if (any(ok)) {
       xy.lm <- lm(y~x)
       abline(xy.lm,col='lightgrey')
       require(ellipse)
       ell <- ellipse(cor(x,y), level = 0.95, scale = c(sd(x),sd(y)), 
centre = c(mean(x),mean(y)))
       polygon(ell,border='red')
     }
}

with the pairs command:
   pairs(df.c,pch=19,
     lower.panel=panel.ellipse,
     diag.panel=panel.hist,upper.panel=panel.cor)

Is this possible to do?

(R 15.2)

Regards

David S

-- 
David K Stevens, P.E., Ph.D.
Professor and Head, Environmental Engineering
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stevens at usu.edu



More information about the R-help mailing list