[R] Bug in xYplot() with method = 'filled bands'

Michael Kubovy kubovy at virginia.edu
Tue Apr 24 16:22:59 CEST 2007

Dear r-helpers,

I have been bitten by a cryptic comment in the help page for xYplot().

Here is some code from Madeline Bauer, one of the authors, which is  
essentailly the code on the help page for xYplot():

# This example uses the summarize function in Hmisc to
# compute the median and outer quartiles.  The outer quartiles are
# displayed using "filled bands"

dfr <- expand.grid(month=1:12, year=c(1997,1998), reps=1:100)
month <- dfr$month; year <- dfr$year
y <- abs(month-6.5) + 2*runif(length(month)) + year-1997
s <- summarize(y, llist(month,year), smedian.hilow, conf.int=.5)

# filled bands: default fill = pastel colors matching solid colors
# in superpose.line (this works differently in R)
xYplot ( Cbind ( y, Lower, Upper ) ~ month, groups=year,
      method="filled bands" , data=s, type="l")

The comment "this works differently in R" should be ammended to a  
more explicit danger sign (otherwise users like myself might find  
themselves wasting a great deal of time). There appear to be two  
differences between S+ and R here: (1) the default colors of the  
bands are not as expected (but they can be changed at will, so that's  
not a serious problem); (2) I have not been able get rid of the  
outline around the filled bands or change their colors to match the  

I would have thought that ...

xYplot ( Cbind ( y, Lower, Upper ) ~ month, groups=year,
      method="filled bands" , data=s, type="l", lwd.bands = 0,
      lty.bands = 0, col.bands = 'white')

... would do the trick.

I even tried to fix the problem in the code of xYplot:

 > panel.XYplot

function (x, y, subscripts, groups = NULL, type = if (is.function 
(method) ||
if (method == "filled bands") {
if (.R.)
grid.polygon(x = c(x, rev(x)), y = c(lower, rev(upper)),
gp = gpar(fill = col.fill, col = col.bands,
lty = lty.bands, lwd = lwd.bands),
default.units = "native")
else polygon(x = c(x, rev(x)), y = c(lower, rev(upper)),
col = col.fill)

Obviously I don't know grid well enough to fix the problem. Help  
would be much appreciated, as well as a more explicit warning on the  
xYplot() help page.

There is, of course, the possibility that there's something wrong  
with my version of R or my OS or my machine. In that case a  
replication or non-replication of this problem on a different OS  
might alert me to this.

R version 2.5.0 RC (2007-04-21 r41269)


attached base packages:
[1] "grDevices" "datasets"  "grid"      "graphics"  "stats"     "utils"
[7] "methods"   "base"

other attached packages:
         coda         lme4       Matrix          car   
cacheSweave       stashR
     "0.10-7"  "0.9975-13"  "0.9975-11"      "1.2-1"         
"0.3"      "0.2-1"
     filehash       digest     circular         boot      gmodels  
      "0.9-4"      "0.2.3"      "0.3-6"     "1.2-27"      
"2.13.2"      "0.1-0"
      reshape          vcd   colorspace      effects         
Hmisc      acepack
      "0.7.2"      "1.0-3"       "0.95"     "1.0-10"      "3.3-1"     
           HH     multcomp      mvtnorm          JGR        
iplots       JavaGD
     "1.18-3"    "0.991-9"      "0.7-5"     "1.4-15"       
"1.0-7"      "0.3-6"
         MASS     gridBase      lattice latticeExtra         
rJava       xtable
     "7.2-33"      "0.4-3"     "0.15-4"      "0.1-6"      
"0.4-15"      "1.4-3"

Michael Kubovy

More information about the R-help mailing list