[R] Vanishing boxplots with transparency and zero margins

Keith Ponting k.ponting at aurix.com
Tue Sep 30 12:09:22 CEST 2008

Dear All,

I am observing unusual behaviour when trying to completely fill a page
with boxplots. The problem only appears when I have both of:
* zero right or bottom margins
* colours with some degree of transparency

I first noticed this on R 2.7.1; it is still happening on a fresh
install of 2.8.0 alpha.
My machine is Windows Vista Business SP1. Output of sessionInfo() is:

R version 2.8.0 alpha (2008-09-26 r46576) 

LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

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

Code reproducing the problem is as follows:

hcl.spread <- function(n,c=40,l=80,twist=0,...)
    ## cf ihaka03colours for choice of hcl
    result <- 0
    if ( n > 0 ){
      angle <- 360/n
      result <- hcl(h=seq(angle/2+twist,360+twist,by=angle),c=c,l=l,...)
    } else {
      stop("number of colours must be positive")
xx <- rep(1:10,10)
yy <- rcauchy(100,location=xx)
  for ( k in 1:n){
    boxplot(yy~xx,pars = list(boxwex = 0.8, staplewex = 0.5, outwex =
## the following works as expected
cols <- hcl.spread(2,twist=-90,c=60,alpha=1)
par <- par(mfrow=c(2,2),mar=c(5,4,3,2))
## transparency, normal margins - OK
cols <- hcl.spread(2,twist=-90,c=60,alpha=0.7)
par <- par(mfrow=c(2,2),mar=c(5,4,3,2))
## no transparency, zero margins - OK
cols <- hcl.spread(2,twist=-90,c=60,alpha=1)
par <- par(mfrow=c(2,2),mar=c(0,0,0,0))
## transparency with zero margins - only the top left plot 
## has any boxes, the remaining plots have only the outliers
cols <- hcl.spread(2,twist=-90,c=60,alpha=0.7)
par <- par(mfrow=c(2,2),mar=c(0,0,0,0))
## it seems to be the right hand column and bottom row which
## are affected however many plots I use:
cols <- hcl.spread(2,twist=-90,c=60,alpha=0.7)
par <- par(mfrow=c(3,4),mar=c(0,0,0,0))
## it seems to be a function of zero margins
## the following bring back respectively right hand column and bottom
cols <- hcl.spread(2,twist=-90,c=60,alpha=0.7)
par <- par(mfrow=c(3,4),mar=c(0,0,0,1e-10))
repeat.box(12) # right hand colum OK, bottom row not
cols <- hcl.spread(2,twist=-90,c=60,alpha=0.7)
par <- par(mfrow=c(3,4),mar=c(1e-10,0,0,0))
repeat.box(12) # bottom row OK, right hand column not
## finally it affects even a single plot
cols <- hcl.spread(2,twist=-90,c=60,alpha=0.7)
par <- par(mfrow=c(1,1),mar=c(0,0,0,0))
repeat.box(1) # outliers only
par <- par(mfrow=c(1,1),mar=c(1e-10,0,0,1e-10))
repeat.box(1) # boxplots as expected

Keith Ponting
Aurix Ltd, Malvern WR14 3SZ  UK

More information about the R-help mailing list