[Rd] grid graphics gpar(fill) argument and jpeg device

Paul Murrell p.murrell at auckland.ac.nz
Thu Dec 8 22:32:46 CET 2005


Hi


Florian Hahne wrote:
> Hi everybody,
> I just notice a strange behaviour of gpar's fill argument when using 
> non-postscript devices:
> The default of the argument is transparent (according to get.gpar("fill")).
> So as expected, the following code draws a nice red rectangle in the 
> middle of my X11 or postscript device.
> 
> pushViewport(viewport(width=0.5, height=0.5))
> grid.rect(gp=gpar(fill="red"))
> grid.rect()
> 
> However, when plotting on  a jpeg device (or any other pixel device), 
> the output of the above code is an empty (=white) rectangle. Obviously 
> the second grid.rect() which should produce a transparent rectangle 
> turns out to be filled white on the jpeg device. When I set the fill 
> argument to NA, the second rectangle is transparent as it is supposed to be.
> 
> grid.rect(gp=gpar(fill="red"))
> grid.rect(gp=gpar(fill=NA))
> 
> Is this a bug or a feature???
> I'm using R version 2.2.0 on a SUSE 10.0 linux machine.


Feature.  The top-level grid viewport (representing the entire device) 
takes starting values for things like text size, background colour, etc 
from the device;  from R version 2.2, this includes using 'fg' and 'bg' 
from the device for gpar(col) and gpar(fill).  This is so that if you 
start a device using something like postscript(bg="red"), the gpar(fill) 
for the top-level grid viewport will be "red".

The default 'bg' for PostScript is "transparent", but for jpeg the 
default 'bg' is "white".

Paul
-- 
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