[R] color blending and transparency
baptiste.auguie at googlemail.com
Wed Feb 3 14:32:41 CET 2010
Adding two semi-transparent colours results in non-intuitive colour
mixing (a mystery for me anyway). Is it additive (light), substractive
(paint), or something else? Consider the following example, depending
on the order of the two "layers" the overlap region is either purple
or dark red. I have no idea why.
# Red below
rect(0.3, 0.5, 1, 1, col=rgb(1, 0, 0, alpha=0.5))
rect(0, 0.5, 0.7, 1, col=rgb(0, 0, 1, alpha=0.5))
# Blue below
rect(0, 0, 0.7, 0.5, col=rgb(0, 0, 1, alpha=0.5))
rect(0.3, 0, 1, 0.5, col=rgb(1, 0, 0, alpha=0.5))
On 3 February 2010 11:15, Jim Lemon <jim at bitwrit.com.au> wrote:
> On 02/03/2010 08:43 PM, bluecuttlefish wrote:
>> I am using ggplot and posted this question at that helplist. It was
>> suggested that I try a more general R-help list for a possible solution to
>> this problem.
>> Within ggplot, I am using geom_area with red and blue and expect where
>> overlap should be purple. But instead, it's dark red.
>> Playing with alpha and with different colors doesn't seem to solve the
>> Here's a very simple reproducible example
>> R --arch x86_64
>> a<-data.frame(pos=z, y=y, x=x)
>> ex<- ggplot(data=a, aes(pos)) +
>> geom_area(aes(y = y),fill="navyblue", alpha = 0.7, position="identity") +
>> geom_area(aes(y = x), fill= "darkred", alpha = 0.7,position="identity" ) +
>> opts(panel.background = theme_rect(fill = "white"))
>> Likewise, with blue and yellow, I would expect overlap to be green.
>> Are there any solutions to this that would allow color overlaps to lead to
>> the "expected" color?
> Hi bluecuttlefish,
> Think ink - should be easy. Only certain devices support transparency. Have
> you tried this on the pdf device?
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help