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
ripley@stats.ox.ac.uk
2003-Mar-10 18:23 UTC
[R] graphics backgrounds from gray to white in png()
Why are you using lattice for a single plot? If you use lattice, you should be using trellis.device(), or at least setting the lattice parameters *after* you open the device. You set the parameters for a screen device (or whatever you had open before). On Mon, 10 Mar 2003, 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-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Deepayan Sarkar
2003-Mar-10 18:47 UTC
[R] graphics backgrounds from gray to white in png()
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