[R] transparent backgound in lattice plots

Jeff D. Hamann jeff.hamann at forestinformatics.com
Sat Sep 10 03:08:34 CEST 2005


I couldn't find this is in the FAQs or in the R archives and I've poked 
around the lattice package manual, but...

I've been trying to figure out how to generate graphics files with a 
transparent background with the lattice package. The code to generate the 
levelplot is fine and I can produce a simple png file with a transparent 
background just fine, but I'm not sure how to generate a png of a lattice 
plot with a transparent backgound.

png( "../images/opt_harvest_pattern_pred.png", bg="transparent" )
main=expression( paste( "Optimal Harvest Pattern ", widehat(V)[saw], ", in 
", m^3 ) )
labs <- paste( rep( "Day", 12 ), 1:12 )
opt.harv.pat.pred <- levelplot( var1.pred~x+y,
                 data=saw.comb,
                 aspect=mapasp(saw.comb),
                 col.regions=terrain.colors(80),
                 main=main,
                 panel = function(...) {
                   panel.levelplot(...)
                   panel.grid(h=-1, v=-1, col="black", lwd=2)
                   panel.text( from.x[par[1:12]],
                              from.y[par[1:12]]+20,
                              labs, color="black", lwd=2, cex=1 )
                   panel.arrows( from.x[par[1:11]], from.y[par[1:11]],
                                from.x[par[2:12]], from.y[par[2:12]],
                                angle=10, col="black", lwd=1 )
                 }
                 )
print( opt.harv.pat.pred )
dev.off()

the png bg="transparent" seems to have no effect here and I'm not sure where 
in the lattice levelplot call to set the background to transparent. I'm sure 
it's obvious....

Help?
Jeff.

---
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon USA 97339-1421
541-754-1428
jeff.hamann at forestinformatics.com
www.forestinformatics.com




More information about the R-help mailing list