[R] color blending and transparency

Thomas Lumley tlumley at u.washington.edu
Wed Feb 3 20:45:05 CET 2010

On Wed, 3 Feb 2010, baptiste auguie wrote:

> Thanks for this complementary information. My head itches slightly
> when reading about these virtual layers with unidirectional absorption
> and reflection properties but I guess that's imputable to my personal
> background as a physicist.

It's not unidirectional, it's just infinitesimal thickness -- if the light didn't hit a pigment particle in the top layer on the way in, it won't on the way out either.  Not realistic, but very physicist ;)

> I still have a few questions,
> - is this behavior documented? (I'm happy to look at the source, but
> I'm not even sure if it's in grDevices, device specific, or somewhere
> else altogether)

Several of the devices delegate the computations to the operating system or viewer, so that's the easiest way to find the algorithm.  It's the Porter-Duff compositing algorithm, the "over" operator.

> - have there been any attempts at implementing other options for
> colour blending? It would be nice to be able to switch between
> additive and substrative colour mixing rules on occasion, but as far
> as I understand the scheme we discussed is hard coded deep into R's
> internals (correct?). An option not to use the background at all in
> the "mixing" / "reflection" process would be great already.

There are some limitations from the ink-on-paper graphics model in R, since the resulting color from n layers must be a function only of the resulting color from n-1 layers and the top color (and not, for example, a function of n).

Also, for PDF and SVG we are basically limited to models that PDF implements automatically, since it isn't feasible to work out which objects overlap and adjust their colors that way.


Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

More information about the R-help mailing list