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

Michael Kubovy kubovy at virginia.edu
Fri Apr 27 03:47:17 CEST 2007

```Hi Sundar,

Thanks for taking a look at this

On Apr 26, 2007, at 1:05 PM, Sundar Dorai-Raj wrote:

>
>
> Michael Kubovy said the following on 4/26/2007 7:20 AM:
>> Dear R-helpers,
>> How do I tell panel.polygon what greoup and panel it applies to
>> whithin
>> xyplot(y ~ x | c, groups = g
>> 	panel = function(x, y, groups, ...){
>> 	        panel.polygon(x = xpol[c, g], y = ypol[c, g],
>> default.units  = 'native')
>> 		panel.xYplot(x, y, groups, ...)
>> 		llines(x = c(1, 6),  y = c(-24.283333, 35.941667), lwd = 2, lty
>> =  3, col = 4)
>>      }
>> x[c, g] and y[c, g] describe the polygon I want plotted for group
>> g  in panel c.
>> _____________________________
>
> I believe you can just do:
>
> panel = function(x, y, subscripts, groups, ...) {
>   ## note addition of subscripts to arguments
>   panel.superpose(xpol, ypol, subscripts, groups,
>                   panel.groups = "panel.polygon",
>                   default.units = "native", ...)
>   panel.xYplot(x, y, subscripts, groups, ...)
>   llines(x = c(1, 6),  y = c(-24.283333, 35.941667),
>         lwd = 2, lty = 3, col = 4)
> }
>
> Also, it would be easier to provide tested answers if you gave a
> reproducible example.

Here is a reproducible example in which I tried (unsuccesfully) to

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)

xyplot(est ~ x | cond, group = grp, data = data, type = 'b',
panel = function(x, y, subscripts, groups, ...){
panel.superpose(c(x, rev(x)), c(upper, rev(lower)),
subscripts, groups,
panel.groups = 'panel.polygon', default.units =
'native', ...)
panel.xyplot(x, y, subscripts, groups, ...)
}
)
# returns: "Error in validGP(list(...)) : Must specify only one of
'font' and 'fontface'", which is incomprehensible to me.
_____________________________
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall