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

Michael Kubovy kubovy at virginia.edu
Fri Apr 27 21:12:49 CEST 2007


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()?

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?

Thanks,
MIchael

On Apr 27, 2007, at 2:25 PM, Deepayan Sarkar wrote:

> On 4/27/07, Michael Kubovy <kubovy at virginia.edu> wrote:
>> Hi Deepayan,
>>
>> Thanks for your advice. This is moving along, however:
>> The following is drawing the same polygons in each panel. I'm trying
>> to get a different polygon (confidence band) for each group in each
>> panel. That's why I thought I would need to pass groups and
>> subscripts to the panel.groups
>>
>> est <- c(1:4, 3:6, 7, 9, 11, 13, 12, 15, 18, 21)
>> cond <- rep(c('a','b'), each = 8)
>> grp <- rep(c('I', 'II'), each = 4, 2)
>> x <- rep(c(.5, .7, .9, 1.1), 4)
>> upper <- est + 1
>> lower = est - 1
>> data <- data.frame(est = est, x = x, cond = cond, grp = grp, upper =
>> upper, lower = lower)
>>
>> my.panel.polygon <- function(..., font, fontface)
>> {
>>     panel.polygon(...)
>> }
>>
>> xyplot(est ~ x | cond, group = grp, data = data, type = 'b',
>>      panel = function(x, y, ...){
>>          panel.superpose(c(x, rev(x)), c(upper, rev(lower)),
>>              panel.groups = 'my.panel.polygon', default.units =
>> 'native', ...)
>>          panel.xyplot(x, y, ...)
>>      }
>> )
>>
>> It's pretty clear that panel.superpose is not getting its x and y
>> values after they are split by group and panel.
>
> You are not even trying to do that; you have
>
>  panel.superpose(c(x, rev(x)), c(upper, rev(lower)), <...>
>
> so your x=c(x, rev(x)) is not the same length as x (and  
> subscripts), and your
> y = c(upper, rev(lower)) is not the same length as anything. Also,
> your upper and lower are being taken from the global env, not data
> (they happen to be the same, but since your data has them, I assume
> you want to use them).
>
> Perhaps you are looking for something like this:
>
>
> panel.bands <-
>    function(x, y, upper, lower,
>             subscripts, ..., font, fontface)
> {
>    upper <- upper[subscripts]
>    lower <- lower[subscripts]
>    panel.polygon(c(x, rev(x)), c(upper, rev(lower)), ...)
> }
>
> xyplot(est ~ x | cond, group = grp, data = data, type = 'b',
>       upper = data$upper,
>       lower = data$lower,
>       panel = function(x, y, ...){
>           panel.superpose(x, y, panel.groups = 'panel.bands', ...)
>           panel.xyplot(x, y, ...)
>       })
>
> -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