[R] gray background in png

Andrew Criswell r-stats at arcriswell.com
Sun Jul 18 19:29:02 CEST 2004


It also seems to work with two lines of code crossed out.

library(lattice)
z <- expand.grid(A = LETTERS[1:8], B = letters[1:6], x = 1, y = 1)

trellis.device(png, file = "test%02d.png") 
# par(bg = "white")
# lset(col.whitebg())
lset(list(background = list(col = "white")))
xyplot(y ~ x | A * B, data = z, layout = c(4, 6))
dev.off()

ANDREW


Deepayan Sarkar wrote:

>On Sunday 18 July 2004 10:29, Liaw, Andy wrote:
>  
>
>>Seems like a bug to me.  I tried setting theme=col.whitebg in
>>arguments to trellis.device, same result.  Setting
>>options(lattice.theme=col.whitebg) also does the same thing.  The
>>same thing happens win.metafile() for me. This is on WinXPPro,
>>R-1.9.1 and
>>    
>>
>
>Definitely a bug, but probably not where you would think. Note that 
>col.whitebg() is misnamed, the background is actually  'transparent'. 
>As far as I can make out, the first plot is the one that's wrong, all 
>the subsequent ones are fine. (The apparent 'grayness' of the 
>background is probably just a feature of your png displayer.) 
>
>The workaround depends on whether you really want a white or transparent 
>background.
>
>
>For transparent:
>
>library(lattice)
>z <- expand.grid(A = LETTERS[1:8], B = letters[1:6], x = 1, y = 1)
>
>trellis.device(png, file = "test%02d.png")
>par(bg = "transparent")
>lset(col.whitebg())
>
>xyplot(y ~ x | A * B, data = z, layout = c(4, 6))
>dev.off()
>
>
>For white:
>
>library(lattice)
>z <- expand.grid(A = LETTERS[1:8], B = letters[1:6], x = 1, y = 1)
>
>trellis.device(png, file = "test%02d.png") 
>par(bg = "white")
>lset(col.whitebg())
>lset(list(background = list(col = "white")))
>
>xyplot(y ~ x | A * B, data = z, layout = c(4, 6))
>dev.off()
>
>
>The reason for this, I think, is that grid seems to use par("bg") for 
>the background of the first plot, but not for the rest. See, for 
>example. the results of 
>
>png(bg = "yellow")
>grid.lines()
>grid.newpage()
>grid.lines()
>dev.off()
>
>I'll have to think about the best way to fix this. 
>
>Deepayan
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
>  
>




More information about the R-help mailing list