geom_area & transparency

4,957 views
Skip to first unread message

squid

unread,
Nov 23, 2009, 11:04:48 AM11/23/09
to ggplot2
Hi,
Is it possible to use two colors in geom_area (for two overlapping
plots) but to have them transparent so as to see clearly what is going
on where they overlap? I attach an example ("Picture 2" in files)
from a journal for what I'd like to achieve.
Thanks,
Squid.

Luciano Selzer

unread,
Nov 23, 2009, 12:53:14 PM11/23/09
to squid, ggplot2
Hi Squid, you could call the geom_area with the alpha option in it
something like:

p+geom_area(alpha=0.5)

Luciano



2009/11/23 squid <bluecut...@gmail.com>:
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2

hadley wickham

unread,
Nov 23, 2009, 12:54:44 PM11/23/09
to Luciano Selzer, squid, ggplot2
And you'll probably want to override the default stacking behaviour with:

p + geom_area(alpha = 0.5, position = "identity")

Hadley
--
http://had.co.nz/

squid

unread,
Dec 17, 2009, 10:26:16 AM12/17/09
to ggplot2
This works really well but I'm wondering if it is possible to have the
"expected" color in areas of overlap.
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 an example

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),size=.1, fill="navyblue", alpha = 0.7,
position="identity") +
geom_area(aes(y = x), size=.1, 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?

Thanks,
Squid.


On Nov 23, 5:54 pm, hadley wickham <h.wick...@gmail.com> wrote:
> And you'll probably want to override the default stacking behaviour with:
>
> p + geom_area(alpha = 0.5, position = "identity")
>
> Hadley
>
> On Mon, Nov 23, 2009 at 11:53 AM, Luciano Selzer
>
>
>
> <luciano.sel...@gmail.com> wrote:
> > Hi Squid, you could call the geom_area with the alpha option in it
> > something like:
>
> > p+geom_area(alpha=0.5)
>
> > Luciano
>

> > 2009/11/23 squid <bluecuttlef...@gmail.com>:

hadley wickham

unread,
Dec 17, 2009, 11:02:19 AM12/17/09
to squid, ggplot2
On Thu, Dec 17, 2009 at 3:26 PM, squid <bluecut...@gmail.com> wrote:
> This works really well but I'm wondering if it is possible to have the
> "expected" color in areas of overlap.
> I am using geom_area with red and blue and expect where they overlap
> should be purple. But instead, it's dark red.

This is related to the colour blending model that R uses. I remember
reading about something that explains this at some point in the past,
but I can't find anything with some searching today.

Hadley

--
http://had.co.nz/

squid

unread,
Feb 2, 2010, 2:14:47 PM2/2/10
to ggplot2
Am reposting the question I wrote a month ago as I'd really like to
solve it. Thanks...

This works really well but I'm wondering if it is possible to have the
"expected" color in areas of overlap.
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 an example

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),size=.1, fill="navyblue", alpha = 0.7,
position="identity") +
geom_area(aes(y = x), size=.1, 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?

Thanks,
Squid.

On Dec 17 2009, 4:02 pm, hadley wickham <h.wick...@gmail.com> wrote:


> On Thu, Dec 17, 2009 at 3:26 PM, squid <bluecuttlef...@gmail.com> wrote:
> > This works really well but I'm wondering if it is possible to have the

> > "expected"colorin areas of overlap.

Mark Connolly

unread,
Feb 2, 2010, 6:56:38 PM2/2/10
to squid, ggplot2
As far as I can tell, you are limited to alpha blending in R. The
rendering you are getting is not wrong, just not what you want. I think
this is more of an R issue than a ggplot issue (at least it should be
addressed as an R issue, then maybe ggplot will evolve to let you send
blending mode in as an argument). You might try a broader group in the
R universe than ggplot2.

baptiste auguie

unread,
Feb 3, 2010, 3:21:13 PM2/3/10
to ggplot2
This triggered an interesting discussion and explanation on R-help,

http://www.mail-archive.com/r-h...@r-project.org/index.html#83970

as far as I can make out, there is little one can do to change the
colour mixing behavior in R. It may be that a specific device could be
made to use a different mixing rule ( tikzDevice comes to mind for its
editable output format ) but I'm not sure how.


Best,

baptiste

Reply all
Reply to author
Forward
0 new messages