[R] xyplot with grid?
Deepayan Sarkar
deepayan.sarkar at gmail.com
Wed May 9 21:55:48 CEST 2007
On 5/9/07, Gav Wood <news at gavofyork.fastmail.fm> wrote:
> Gabor Grothendieck wrote:
> > Add the argument
> >
> > type = c("p", "g")
> >
> > to your xyplot call.
>
> So what's the easiest way to place a line at x=3 (ala "abline(v=3)") to
> the graph?
xyplot(x~y,data.frame(x=1:9,y=1:9,z=sort(rep(c('A','B','C'),3))),
type = c("p", "g"),
panel = function(...) {
panel.xyplot(...)
panel.abline(v = 3)
},
groups=z,auto.key=list(columns=3))
or
xyplot(x~y,data.frame(x=1:9,y=1:9,z=sort(rep(c('A','B','C'),3))),
panel = function(...) {
panel.grid(h = -1, v = -1)
panel.abline(v = 3)
panel.xyplot(...)
},
groups=z,auto.key=list(columns=3))
depending on whether you are going through the intermediate example or not.
> After calling the xyplot call, the panel.* functions seem to
> work only in device coordinates.
No, they work in native coordinates, you just happen to be in a
"viewport" where they are the same as the device coordinates. Note
that your expectations seem to be based on the traditional graphics
model with only one panel, which is not meaningful in multipanel
plots, like, say,
xyplot(x~y|z,data.frame(x=1:9,y=1:9,z=sort(rep(c('A','B','C'),3))))
If you wish to modify a lattice plot after it has been plotted (which
is justifiable only in circumstances where you want some sort of
interaction), see
?trellis.focus
-Deepayan
More information about the R-help
mailing list