[R] xyplot with grid?

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed May 9 20:34:45 CEST 2007


On Wed, 2007-05-09 at 19:13 +0100, Gav Wood wrote:
> > Giving a reproducible example would be a good start.
> 
> Ok, what's the easiest way to get a grid (ala grid()) on this graph?
> 
> xyplot(x~y,data.frame(x=1:9,y=1:9,z=sort(rep(c('A','B','C'),3))),
>      groups=z,auto.key=list(columns=3))
> 
> Bish bosh,

Er, write your own panel function:

xyplot(x~y,data.frame(x=1:9,y=1:9,z=sort(rep(c('A','B','C'),3))),
       groups=z,auto.key=list(columns=3), h = -1, v = -1,
       panel = function(x, y, ...) {
       panel.grid(...)
       panel.xyplot(x, y, ...)
     })

Not sure if that is the easiest way, or the best, but that's how I've
learnt to use lattice recently. The v and h arguments are passed to
panel.grid as part of "..." and just tell it to plot the grids at the
tick marks.

> 
> Gav

HTH Gav,

Gav

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list