Hello,
Coming against my ignorance of lattice
graphics as someone who learned R after ggplot2
came on the scene. I maintain a package that relies on an older package written using lattice
graphics.
I would like the outputs to be transparent, but it appears that the transparency only applies to the white plot area, not the actual rasters.
The code looks like this:
plt <- openair::polarPlot(openair::mydata, alpha = .5)
png(filename = "testplot.png", bg = "transparent")
plot(plt)
dev.off()
And putting the output, "testplot.png", over a blue square looks like this. Note that the actual surface isn't transparent, it is just washed out.
The code for openair::polarPlot()
can be found here, but I'm not expecting anyone to go through it unless you are particularly keen! The relevant part is reproduced below, where transparency is controlled using alpha.regions
.
panel.levelplot(
x, y, z,
subscripts,
at = col.scale,
pretty = TRUE,
col.regions = col,
labels = FALSE, alpha.regions = alpha
)
Interestingly, this appears to "just work" on Mac computers, but it doesn't play ball on Windows machines and you get this "washed out" appearance.
I appreciate one answer is "use ggplot2
" which we are working on, but at this stage I'd prefer a fix within lattice to avoid all of the various knock-on effects of refactoring openair
just for the sake of fixing transparency.
Note that I am in the position to make changes to openair
if needed.
Cheers,
Jack