[R] xyplot() and controlling panel.polygon()

Michael Kubovy kubovy at virginia.edu
Fri Apr 27 22:58:07 CEST 2007


I can't thank you enough! (I am also grateful to Sundar Dorai-Raj and  
Bert Gunter for their initial responses.)

On Apr 27, 2007, at 4:14 PM, Deepayan Sarkar wrote:

> On 4/27/07, Michael Kubovy <kubovy at virginia.edu> wrote:
>> Hi Deepayan,
>>
>> Your solution works, anf the polygon are drawn where I wanted them to
>> go. I thought that I could figure out how to gain control over the
>> colors of the four ensuing polygons (I'm trying to get two lighter
>> shades of the lines).
>>
>> I've tried, for example, to see if I could control the color of the
>> polyon outline, by adding border = 'red' to panel.polygon. That
>> didn't work. Does it work only in lpolygon()?
>
> No. This is a bug, and the border color can currently only be black or
> transparent (but it's easy to find and fix the bug; lpolygon is very
> short, so just write a replacement).
>
> However, panel.superpose recognizes and splits certain graphical
> parameters; border is not among them, but fill is. So you could do:
>
> my.panel.bands <-
>    function(x, y, upper, lower,
>             fill, col,
>             subscripts, ..., font, fontface)
> {
>    upper <- upper[subscripts]
>    lower <- lower[subscripts]
>    panel.polygon(c(x, rev(x)), c(upper, rev(lower)),
>                  col = fill, border = FALSE,
>                  ...)
> }
>
> xyplot(est ~ x | cond, group = grp, data = data, type = 'b',
>       col = c("#0080ff", "#ff00ff"),
>       fill = c("#bbddff", "#ffbbff"),
>       upper = data$upper,
>       lower = data$lower,
>       panel = function(x, y, ...){
>           panel.superpose(x, y, panel.groups = 'my.panel.bands', ...)
>           panel.xyplot(x, y, ...)
>       })
>
>
>> I often can figure things out on my own, but obviously there's
>> something fundamental that I'm not getting about inheritance and
>> passing in these sorts of objects. I've been trying to get it from
>> the help pages and from Murrell's book, but neither offers enough of
>> a cookbook for me to figure these things out. Is there something I
>> should have read?
>
> The concepts are all there in the help page (but it's often difficult
> to put them together). The main points are:
>
> (1) unrecognized arguments get passed on to the panel function as is
> (2) subscripts give indices of x, y, etc in the original data frame
>
> (the implication being that if you have another column from the
> original data frame, such as upper and lower in your example, indexing
> by subscripts will give you the matching subset). Other than that, the
> panel functions have to do their own work (and what they do should
> ideally be documented); nothing is enforced, so nothing is guaranteed.
>
> This sort of thing doesn't get used often enough for examples to be
> easily found. The following demo in lattice might be helpful.
>
> file.show(system.file("demo/intervals.R", package = "lattice"))
>
> -Deepayan

_____________________________
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
         McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766
WWW:    http://www.people.virginia.edu/~mk9y/



More information about the R-help mailing list