[R] color blending and transparency

Jim Lemon jim at bitwrit.com.au
Wed Feb 3 11:15:01 CET 2010


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 they
> overlap should be purple. But instead, it's dark red.
>
> Playing with alpha and with different colors doesn't seem to solve the
> problem.
>
> Here's a very simple reproducible example
>
> R --arch x86_64
>
> library(ggplot2)
>
> x<-c(24,55,69,73)
> y<-c(44,56,12,90)
> z<-c(1,2,3,4)
> 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"))
>
> ex
>
> 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?

Jim



More information about the R-help mailing list