Skip to content

Defining range of x and y axis in pairs()

2 messages · Christian Zinsmeister, Brian Ripley

#
Hi,

I have a problem to define the range of x and y axis in pairs() for my
scatterplots. In low-level plots I can specify that by providing xlim
and ylim. This also works for pairs() even if warnings tell me that it
doesn't (see below). 

But if I add upper.panel and/or lower.panel it doesn't work - I get an
error message saying that there's an error in "upper.panel
(as.vector(x[, j]), as.vector(x[, i]), ...)"!? 

I know that (according to ?pairs) graphical parameters can be passed to
pairs() and xlim/ylim are *not* graphical parameters - I just wonder
why it anyway works in the first case. 

Can anyway tell me how to adjust my pairs statement either using
xlim/ylim in a different way or by using totally different options?
(I'm a newbie to R)


# This works!
pairs(x, panel=points, xlim=c(-2,2));

# This one doesn't work
pairs(x, panel=points, xlim=c(-2,2), lower.panel=panel.cor,
upper.panel=panel.smooth);

# this is the function for lower.panel
    panel.cor <- function(x, y)
    {
        usr <- par("usr"); on.exit(par(usr))
        par(usr = c(0, 1, 0, 1))
        txt <- cov(x, y, use="pairwise.complete.obs");
        text(0.5, 0.5, txt);}
   }

Thanks!
#
Your panel function is missing a ... argument, hence the difference in the 
two cases.

As to why it works, as someone once said, it does `for some value of 
"work"'.  Amongst the many places xlim gets passed is one that set the 
scale on each panel.  Another place it gets sent is to your panel 
function.
On Tue, 18 Oct 2005, Christian Zinsmeister wrote:

            
^^^