user1424739
user1424739

Reputation: 13675

How to make colors of overlaping regions be independent of the plot order?

plot.new()
library(scales)
rect(0,0,.2,1, col=alpha('red', .5))
rect(.1,0,.3,1, col=alpha('blue', .5))
rect(.6,0,.8,1, col=alpha('blue', .5))
rect(.5,0,.7,1, col=alpha('red', .5))

As you can see, the two overlapping regions (x in (0.1,0.2) and x in (.6, .7)) are of different colors. The only difference is the plot order. Is there a way to mix the color of overlapping region, so that the final color is independent of the plot order of the overlapping regions.

enter image description here

Upvotes: 1

Views: 66

Answers (1)

G5W
G5W

Reputation: 37641

The short answer is "No".

What happens when you print with alpha=0.5? You get 50% of the color you are printing and 50% of whatever is behind it. So if you print first red and then blue, the red gives 50% red plus 50% background = white. Then the blue gives 50% blue plus 50% background, which was 50% red and 50% white so you end up with 50% blue, 25% red and 25% white. If you do it in the opposite order you get 50% red, 25% blue and 25% white.

Upvotes: 1

Related Questions