[R] graphics backgrounds from gray to white in png()

Deepayan Sarkar deepayan at stat.wisc.edu
Mon Mar 10 19:47:10 CET 2003


You need to change the (lattice) background setting AFTER starting the png() 
device (lattice maintains separate settings for different devices). 

If you use png() to start subsequent devices, the same settings will be 
re-used. (The alternative is to use trellis.device(), which is the more 
traditional but not-really-necessary-in-lattice way, in which case by default 
the settings will revert back to the grey background every time a new device 
is started.)

On Monday 10 March 2003 11:48 am, Scot W McNary wrote:
> Hi,
>
> I'm trying to make a png file of a histogram.  I would like a white
> background in the final product but end up producing a gray one, despite
> setting what I think are the correct parameters.  Suggestions for how to
> properly set a white background would be welcome.
>
> Thanks in advance,
>
> Scot
>
>
> # for non-lattice
>
> > par("bg"="white")
> > par("bg")
>
> [1] "white"
>
> # for lattice
> background<-trellis.par.get("background")
> background$col<-"white"
> trellis.par.set("background",background)
>
> > trellis.par.get("background")
>
> $col
> [1] "white"
>
> # produces gray background in png, but white when plotted in active device
>
> > png(filename = "c:/windows/temp/test.png", width=480, height=640,
>
> + pointsize = 10, bg="white")
>
> > histogram(rnorm(500))
> > dev.off()
>
> windows
>       2
>
> Vitals:
> > R.version
>
>          _
> platform i386-pc-mingw32
> arch     i386
> os       mingw32
> system   i386, mingw32
> status
> major    1
> minor    6.2
> year     2003
> month    01
> day      10
> language R
>
>
> --
>   Scot W. McNary  email:smcnary at charm.net
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list