[R] Drawing rectangles in multiple panels

deepayan.sarkar at gmail.com deepayan.sarkar at gmail.com
Wed Jul 11 20:07:25 CEST 2007


On 7/11/07, Jonathan Williams <williams222 at llnl.gov> wrote:
> Deepayan,
>
> Thanks for the clarification.  The rectangles are completely external
> to the panel data, and correspond to 90% confidence intervals built
> from training data, to be overlaid on these graphs of the test data.

Right. So if you have that information in a single object (say a
list), you can specify that as an argument to xyplot (or whatever),
and capture that in the panel function to then index it. E.g.


rectInfo <-
    list(matrix(runif(4), 2, 2),
         matrix(runif(4), 2, 2),
         matrix(runif(4), 2, 2))


panel.qrect <-
    function(x, y, ..., rect.info)
{
    ri <- rect.info[[packet.number()]]
    ## if you have more than one conditioning variable, this might be
    ## something like
    ## ri <- do.call("[", list(rect.info, as.list(which.packet())))[[1]]
    panel.rect(ri[1, 1], ri[1, 2], ri[2, 1], ri[2, 2],
               col = "grey86", border = NA)
    panel.xyplot(x, y, ...)
}


xyplot(runif(30) ~ runif(30) | gl(3, 10),
       rect.info = rectInfo,
       panel = panel.qrect)

-Deepayan



More information about the R-help mailing list