[R] using alpha transparency for lines in levelplot

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Mar 27 05:39:32 CEST 2007


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



More information about the R-help mailing list