[R] How to get transparent colors to sum to complete opacity?

Andrew Crane-Droesch andrewcd at gmail.com
Mon Dec 17 09:55:52 CET 2012


Dear List,

I want to use transparency in R to represent downweighting of 
observations based on clusters (repeated observations in a dataset).  
Some clusters will have identical covariate values in a parameter space 
-- in the 2D x,y case, these represent a bunch of semi-tranparent dots 
in the same place.  I'd like these overlapping dots to be completely 
opaque.  In other cases, the clusters don't have overlapping covariates, 
so when these dots are scattered all around, I want them to be somewhat 
transparent.

But it seems clear that transparency isn't additive.  For example, four 
dots with transparency set to .25 don't add to complete opacity:

x = c(1,1,1,1)
y = c(1,1,1,1)
w = .25
plot(x,y,pch=16,col=rgb(0,0,1,.25,maxColorValue=1),cex=3,xlim=c(.8,2))

My question is the following: what function would I transform "w" by to 
make it so that 4*f(w) = fully opaque?

The following would suggest f(w) = w^.5, but I'd appreciate if someone 
could confirm for applications outside this little example, and give me 
a sense of how this all works, and is intended to work.

x = c(1,1,1,1)
y = c(1,1,1,1)
f = 0
plot(x,y,pch=16,col=rgb(0,0,1,(.25),maxColorValue=1),cex=3,xlim=c(.8,2))
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)
x=x+.1; f=f-.1
points(x,y,pch=16,col=rgb(0,0,1,(.25)^(1+f),maxColorValue=1),cex=3)

Thanks,
Andrew



More information about the R-help mailing list