[Rd] gpar fill and transparency on devices
Paul Murrell
p.murrell at auckland.ac.nz
Fri Aug 6 00:54:47 CEST 2010
Hi
The help page for "Working with Viewports" (e.g., pushViewport()) has a
brief mention when talking about the ROOT viewport ...
"The viewport tree always has a single root viewport (created by the
system) which corresponds to the entire device (and default graphical
parameter settings)."
... which is a reasonable place for it because this is a feature of the
gpar of the ROOT viewport, not of gpars in general. That mention might
be a bit hard to find, but a very similar statement is also made in the
Section on Viewports in the R Graphics book. That in turn might be hard
to find if you don't have the book, but that chapter is also available
online (http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter5.pdf)
It might be worth adding something more explicit about this sort of
gotcha ...
"Some devices have different default graphics parameter settings, so it
is not safe to assume that the ROOT viewport will be identical on
different devices."
... ?
Paul
On 5/08/2010 8:14 a.m., baptiste auguie wrote:
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
More information about the R-devel
mailing list