Hello, I'm having trouble with using the alpha channel for transparency with lines with lattice levelplots. If I use transparency via the alpha argument to rgb to overplot lines on levelplot the transparent colour affects all of the region colours in the plot. Can anyone explain why the difference in region colours? #### Warning: this code attempts to create PDF files in working directory - they may be downloaded, see below library(lattice) ## prepare data data(volcano) xy <- expand.grid(x = 1:nrow(volcano), y = 1:ncol(volcano)) xy$z <- as.vector(volcano) ## panel function to add lines with grey(0.3) my.panel <- function(...) { panel.contourplot(...); panel.xyplot(1:60, runif(60, 1, 60), type = "l", lwd = 3, col = grey(0.3)) } ## this works fine pdf("plot.pdf", version = "1.4") levelplot(z~x+y, xy, panel = my.panel) dev.off() ## panel function to add lines with grey transparency my.paneltransp <- function(...) { panel.contourplot(...); panel.xyplot(1:60, runif(60, 1, 60), type = "l", lwd = 3, col = rgb(0.3, 0.3, 0.3, 0.5)) } ## this results in grey bleeding on the coloured regions of the plot pdf("alpha.pdf", version = "1.4") levelplot(z~x+y, xy, panel = my.paneltransp) dev.off() I've put the pdfs created here for reference: http://staff.acecrc.org.au/~mdsumner/R/ Cheers, Mike. I'm using Windows XP, SP2: sessionInfo() R version 2.4.1 (2006-12-18) i386-pc-mingw32 locale: LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252 attached base packages: [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" [7] "base" other attached packages: lattice "0.14-16"
On 3/26/07, Michael Sumner <mdsumner at utas.edu.au> wrote:> Hello, I'm having trouble with using the alpha channel for transparency > with lines with lattice levelplots. > > If I use transparency via the alpha argument to rgb to overplot lines on > levelplot the transparent colour affects all of the region colours in the > plot.I don't understand what you are trying to say. Here's a modified version of your code: ------------------ ## panel function to add lines with grey(0.3) my.panel <- function(...) { panel.xyplot(1:60, runif(60, 1, 60), type = "l", lwd = 3, col = grey(0.3)) panel.contourplot(...); panel.xyplot(1:60, runif(60, 1, 60), type = "l", lwd = 3, col = grey(0.3)) } ## panel function to add lines with grey transparency my.paneltransp <- function(...) { panel.xyplot(1:60, runif(60, 1, 60), type = "l", lwd = 3, col = rgb(0.3, 0.3, 0.3, 0.5)) panel.contourplot(...) panel.xyplot(1:60, runif(60, 1, 60), type = "l", lwd = 3, col = rgb(0.3, 0.3, 0.3, 0.5)) } pdf("alpha.pdf", version = "1.4") ## this works fine levelplot(z~x+y, xy, panel = my.panel) ## this doesn't? levelplot(z~x+y, xy, panel = my.paneltransp) dev.off() ------------------ and the resulting 2-page PDF file is at http://dsarkar.fhcrc.org/R/alpha.pdf I don't see any evidence of transparency in the 'region' colors (the lines behind the level plot never show up). Are you sure whatever you are seeing is not an artifact of your display application? Deepayan