[Rd] gpar fill and transparency on devices

baptiste auguie baptiste.auguie at googlemail.com
Wed Aug 4 22:14:28 CEST 2010


Dear list,

I'm puzzled by the graphical output in the following example,

library(grid)

foo <- function(){
  grid.rect(gp=gpar(fill="black"))
  print(get.gpar()$fill)
  grid.rect(width=0.2,height=0.2)
}

png("test.png", bg = "transparent")
foo()
dev.off()

png("test1.png", bg = "white")
foo()
dev.off()


It seems that the default value of gpar()$fill is set according to the
device background. I couldn't find this documented in ?gpar or in
?png, and it caused a rather puzzling bug in my code (the pdf() output
was OK, whilst the png output (default bg to white) was seemingly
empty because covered by a white rectangle.)

Best regards,

baptiste



More information about the R-devel mailing list