Dear R-users, I am trying to produce trellis (png, or jpeg) graphs with transparent background, but I cannot manage to make that happen. I tried to play around with themes but to no avail. Any advise on the following example will be greatly appreciated: Thank you Sebastien #### library(lattice) df <- data.frame(a=rep(1:4,4), b=rep(1:4,4), c=rep(1:4,each=4)) settings <- standard.theme() settings <- modifyList(settings, list(background=list(alpha=1, col="transparent"))) str(settings) trellis.device(png, file="test.png", theme=settings) myplot<-xyplot(b~a|c, data=df) print(myplot) dev.off() ####
Just replying to bring back some attention on my post, which might have slept through on Saturday. Thank you for your help. ----- Mail Original ----- De: pomchip at free.fr ?: r-help at stat.math.ethz.ch Envoy?: Samedi 1 Ao?t 2009 15h48:24 GMT -05:00 USA/Canada - ?tats de l'Est Objet: Transparency and trellis device Dear R-users, I am trying to produce trellis (png, or jpeg) graphs with transparent background, but I cannot manage to make that happen. I tried to play around with themes but to no avail. Any advise on the following example will be greatly appreciated: Thank you Sebastien #### library(lattice) df <- data.frame(a=rep(1:4,4), b=rep(1:4,4), c=rep(1:4,each=4)) settings <- standard.theme() settings <- modifyList(settings, list(background=list(alpha=1, col="transparent"))) str(settings) trellis.device(png, file="test.png", theme=settings) myplot<-xyplot(b~a|c, data=df) print(myplot) dev.off() ####
Hi Deepayan, Thank for you reply. I am a little bit confused now. In the one hand, the trellis.device function has lost his bg argument as explained in the Note section of ?trellis.device, but the background info provided by a theme does not seem to impact the background of the device. In the other hand, png has a bg argument that works great but no "theme" capabilities as far as I could see. Do you see a way to reconcile both sides of the problem? Sebastien ----- Mail Original ----- De: "Deepayan Sarkar" <deepayan.sarkar at gmail.com> ?: pomchip at free.fr Cc: r-help at stat.math.ethz.ch Envoy?: Mercredi 5 Ao?t 2009 12h38:30 GMT -05:00 USA/Canada - ?tats de l'Est Objet: Re: [R] Transparency and trellis device On 8/5/09, pomchip at free.fr <pomchip at free.fr> wrote:> Just replying to bring back some attention on my post, which might have slept > through on Saturday. > > Thank you for your help. > > > ----- Mail Original ----- > De: pomchip at free.fr > ?: r-help at stat.math.ethz.ch > Envoy?: Samedi 1 Ao?t 2009 15h48:24 GMT -05:00 USA/Canada - ?tats de l'Est > Objet: Transparency and trellis device > > > Dear R-users, > > I am trying to produce trellis (png, or jpeg) graphs with transparent background, but > I cannot manage to make that happen. I tried to play around with themes but to no > avail. Any advise on the following example will be greatly appreciated:This has nothing to do with trellis, your png device must be set up with a transparent canvas when it is started. See the second paragraph in the "Details" section of ?png, but basically png("test.png", bg = "transparent") -Deepayan
One thing that I did not mention is that my themes contain additional settings (like margin definitions). By looking at the code of trellis.device, it look like the operation of this function can be simplified a device opening followed by a trellis.par.set call. Am I correct? If so, I think I could replace my trellis.device call by the sequence png("foo.png", bg="transparent") / trellis.par.set(mytheme). Sebastien ----- Mail Original ----- De: "Deepayan Sarkar" <deepayan.sarkar at gmail.com> ?: pomchip at free.fr Cc: r-help at stat.math.ethz.ch Envoy?: Mercredi 5 Ao?t 2009 13h16:54 GMT -05:00 USA/Canada - ?tats de l'Est Objet: Re: [R] Transparency and trellis device On 8/5/09, pomchip at free.fr <pomchip at free.fr> wrote:> Hi Deepayan, > > Thank for you reply. > I am a little bit confused now. In the one hand, the trellis.device function has lost his bg argument as explained in the Note section of ?trellis.device, but the background info provided by a theme does not seem to impact the background of the device. In the other hand, png has a bg argument that works great but no "theme" capabilities as far as I could see. > > Do you see a way to reconcile both sides of the problem?There's no conflict. The "bg" argument of png() (and most other devices) is a "canvas color" that is handled by the device driver. The lattice "background" setting controls a background rectangle plotted by lattice: png("foo.png", bg = "transparent") xyplot(1 ~ 1, par.settings = list(background = list(col = "yellow"))) dev.off() Obviously, plotting a transparent rectangle over a white canvas (which you were effectively doing) will not make the canvas transparent. -Deepayan
Possibly Parallel Threads
- Relationships between png resolution, axis.text$cex trellis setting, and paddings
- Problem to remove loops in a routine
- Changing size of lattice plot?
- Overlaying lattice graphs
- Lattice: Superimposing histograms with different colors and transparency effects