[R] How to get transparent colors to sum to complete opacity?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Dec 17 13:58:40 CET 2012
Look up 'alpha-blending' to see how this works. And remember that the
sRGB colorspace used has non-linear transformations too.
Superposing a finite set of semi-transparent dots will never give an
opaque one (and that is true of physical dots too).
On 17/12/2012 08:55, Andrew Crane-Droesch wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list