[Rd] windows device transparency issue

From: Austin, Matt <maustin_at_amgen.com>
Date: Thu, 27 Sep 2007 16:46:00 -0700


I read in a thread in r-help today that the windows device in 2.6 supports transparency, so I tried an example and had some issues. The density plots should be filled with transparent color in the following example (similar to the points), however the color is "fully" transparent. This works in the Cairo device, but not in the windows device.  



Matt Austin

Statistician, Amgen Inc.    

Example of problem derived from example(layout) code.  



x <- pmin(3, pmax(-3, rbeta(5000,1,5)))

y <- pmin(3, pmax(-3, c(rnorm(2500, .25, 1), rnorm(2500))) )

trtp.f <- factor(rep(c("Placebo", "Not Placebo"), each=2500), levels=c("Placebo", "Not Placebo"))  

xdens <- tapply(x, trtp.f, density, na.rm=TRUE)

ydens <- tapply(y, trtp.f, density, na.rm=TRUE)  

topx <- max(unlist(lapply(xdens, function(x) max(x$y))))

topy <- max(unlist(lapply(ydens, function(x) max(x$y))))  

xrange <- range(x, na.rm=TRUE)

yrange <- range(y, na.rm=TRUE)  

nf <- layout(matrix(c(2,0,1,3),2,2,byrow=TRUE), c(3,1), c(1,3), TRUE)  

par(mar=c(4,4,0,0), oma=c(0,0,0,0))  

getcolors <- rainbow(length(levels(trtp.f)), alpha=.5)

plot(x, y, xlim=xrange, ylim=yrange,xlab="X value", ylab="Y value", pch=21, bg=getcolors[as.numeric(trtp.f)])  


plot(x=xrange, axes=FALSE, xlim=xrange, ylim=c(0, topx), xlab="", ylab="")

#lapply(xdens, lines)  

for(i in 1:length(xdens)){

  dat <- xdens[[i]]

  polygon(x=c(min(dat$x), dat$x, max(dat$x)) , y=c(0, dat$y, 0), col= rainbow(length(xdens), alpha=.5)[i])



plot(x=yrange, axes=FALSE, ylim=yrange, xlim=c(0, topy), xlab="", ylab="")  

for(i in 1:length(ydens)){

  dat <- ydens[[i]]

  polygon(y=c(min(dat$x), dat$x, max(dat$x)) , x=c(0, dat$y, 0), col=rainbow(length(ydens), alpha=.5)[i])   



Other Info:  

platform i386-pc-mingw32

arch i386

os mingw32

system i386, mingw32

status RC

major 2

minor 6.0

year 2007

month 09

day 26

svn rev 42991

language R

version.string R version 2.6.0 RC (2007-09-26 r42991)

        [[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 27 Sep 2007 - 23:50:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 28 Sep 2007 - 12:41:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.