[R] subset inside a lattice plot using panel.lines

Deepayan Sarkar deepayan.sarkar at gmail.com
Mon Aug 4 21:41:35 CEST 2008


On Mon, Aug 4, 2008 at 8:44 AM, Mark Difford <mark_difford at yahoo.co.uk> wrote:
>
> Hi Michael,
>
>>> Pulling my hair out here trying to get something very simple to work. ...
>
> I can't quite see what you are trying to do [and I am not sure that you
> clearly state it], but you could make things easier and simpler by (1)
> creating a factor to identify your groups of rows more cleanly and (2) by
> using the groups= argument in lattice.
>
> ## Something along these lines
> copyDat <- originalDat
> copyDat$newFac <- gl(2, 387, 774, labels=c("A","B"))
>
> xyplot(response ~ predictor|maybe.condition, data=copyDat, groups=newFac)

Right, and using 'row' directly should also work (although not with as
good possibilities for annotation):

xyplot(response ~ predictor|maybe.condition, data=copyDat,
       groups=(row <= 387), type = c("l", "g"))

If you need a custom panel function, try using panel.groups:

xyplot(response ~ predictor|maybe.condition, data=copyDat,
       groups=(row <= 387),
       panel = panel.superpose,
       panel.groups = function(...) {
          panel.grid(h = -1, v = -1, lty = 3)
          panel.lines(...)
       })

-Deepayan



More information about the R-help mailing list