[R] Putting regression lines on SPLOM

Deepayan Sarkar deepayan at stat.wisc.edu
Fri Sep 5 19:45:54 CEST 2003


On Friday 05 September 2003 10:04 am, Ted Harding wrote:
> Another query:
>
> I'm now trying to have the x- and y-axes all on the same scale
> (0:15) in every panel, whereas the default behaviour of splom
> is to scale them according to the ranges of the individual
> variables in each panel.
>
> So I tried (emulating the responses to my earlier query):
>
>   splom(log(1+DF), panel = function(x, y, ... ) {
>         panel.xyplot(x, y, xlim=c(0,15),ylim=c(0,15))
>        })
>
> And it appears that the 'xlim' and 'ylim' specifications are
> ignored (i.e. the behaviour is exactly the same as
>   splom(log(1+DF)).
>

Yes, this is what I briefly mentioned in my earlier message. 

panel.xyplot does not accept arguments called xlim and ylim (see below), so 
it's not surprising that this didn't work. The panel function is responsible 
for doing the plotting only; the plotting area, along with appropriate scales 
and axes, have to be set up beforehand.

Unfortunately, the current implementation of splom (in particular the 
panel.pairs function) does not allow you to do what you want in any other way 
either (however, read on for a solution).

The usual control of axis limits in xyplot-like functions can be done in two 
ways. One, via the prepanel function, which conceptually has access to all 
the data the panel function has, and can use that to decide what the 
appropriate limits should be. The other way is explicit specification via the 
scales argument (for which xlim and ylim are a shorthand).

The prepanel function returns separate limits for x and y axes. This does not 
translate to splom, since each limit is used on both the x and y axes. 
However, it is natural to add a new optional argument, which would be a  
function that would decide on the limits for each variable in the data frame, 
to be used as both x and y limits. This feature was missing till now, but I 
have added something for the next release (source() the attached file to use 
it), which will allow you to do:

splom(log(1+DF),
      prepanel.limits = function(x) c(0, 15),
      panel = function(x, y, ... ) {
          panel.xyplot(x, y, ...)
      })

Another natural thing to do would be to extend the scales$limits option to the 
pscales argument in splom. I'll look into it.


> ?panel.xyplot refers you to ?xyplot for "further arguments",
> and ?xyplot certainly specifies the above form for specifying
> x- and y-limits. I think ...

Where exactly does it do that ? xyplot is in the "See Also" section, but how 
does that imply that arguments accepted by xyplot can be given to 
panel.xyplot ? And I don't see the phrase "further arguments" anywhere in the 
help page for panel.xyplot.

If there's anything in the documentation that even suggests that xlim and ylim 
can be passed to panel functions, that's definitely misleading, and I would 
appreciate it if you could point out any such confusing statements.

Deepayan




More information about the R-help mailing list