[R] Drawing rectangles in multiple panels

Bert Gunter gunter.berton at gene.com
Wed Jul 11 19:30:55 CEST 2007


Deepayan et. al.:

A question/comment: I have usually found that the subscripts argument is
what I need when passing *external* information into the panel function, for
example, when I wish to add results from a fit done external to the trellis
call. Fits[subscripts] gives me the fits (or whatever) I want to plot for
each panel. It is not clear to me how the panel layout information from
panel.number(), etc. would be helpful here instead. Am I correct? -- or is
there a smarter way to do this that I've missed?

Cheers,

Bert

Bert Gunter
Genentech Nonclinical Statistics


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
deepayan.sarkar at gmail.com
Sent: Wednesday, July 11, 2007 10:04 AM
To: Jonathan Williams
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Drawing rectangles in multiple panels

On 7/11/07, Jonathan Williams <williams222 at llnl.gov> wrote:
> Hi folks,
>
> I'm having some trouble understanding the intricacies of panel
> functions.  I wish to create three side-by-side graphs, each with
> different data-- so far, so good: I rbind() the data, add a column of
> subscripts as a conditioning variable, load up the lattice package,
> specify either a c(3,1) 'layout' or work through 'allow.multiple' and
> 'outer' and I'm good to go.
>
> But now I wish to add three rectangles to each plot, which will be in
> different places on each panel, and I'm terribly stuck.  I can guess
> this requires defining a panel function on the fly, but none of my
> attempts are working.  Suggestions?

You haven't told us what determines the rectangles (only that they are
different in each panel). If they are completely driven by panel data,
here's an example:

panel.qrect <-
    function(x, y, ...)
{
    xq <- quantile(x, c(0.1, 0.9))
    yq <- quantile(y, c(0.1, 0.9))
    panel.rect(xq[1], yq[1], xq[2], yq[2],
               col = "grey86", border = NA)
    panel.xyplot(x, y, ...)
}

xyplot(Sepal.Length ~ Sepal.Width | Species, iris,
       panel = panel.qrect)

If the rectangles are somehow determined externally, you probably want
to use one of the accessor functions described in help(panel.number).
There are good and bad (i.e. less robust) ways to use these, but we
need to know your use case before recommending one.

-Deepayan

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list