Discussion:
geom_density legend symbols
Gregory
2011-08-14 18:37:19 UTC
Permalink
Hello,

I'm creating a single graph with 5 overlapping density plots. Each is
given its own color through the "colour" parameter in aes(). The
resulting legend is a square box with a 45 degree line through it in
the corresponding colors. I would like, however, for the box to be
fully fill in, rather than just have a thin 45 degree line through it.
I wouldn't mind having the legend symbol be a filled-in circle as
well. Is this possible in ggplot2? I'll use the development version if
needed: the previous version of this project I did in lattice, and I
like to move to ggplot2, but I'm required to keep consistent-looking
graphs.

Thanks,
Gregory
Dennis Murphy
2011-08-15 00:01:56 UTC
Permalink
Hi:

I'm not sure this is what you had in mind, but consider the following example:

dd <- data.frame(gp = factor(rep(1:5, each = 100)), y = rnorm(500))
ggplot(dd, aes(x = y, fill = gp, colour = gp)) +
theme_bw() +
geom_density(alpha = 0.3) +
scale_colour_manual(breaks = levels(dd$gp), values = NA)

The last line of code removes the outlines from the legend but also
from the plot. The alpha transparency is to avoid (partial) obscurity
of one density plot by another.

HTH,
Dennis
Post by Gregory
Hello,
I'm creating a single graph with 5 overlapping density plots. Each is
given its own color through the "colour" parameter in aes(). The
resulting legend is a square box with a 45 degree line through it in
the corresponding colors. I would like, however, for the box to be
fully fill in, rather than just have a thin 45 degree line through it.
I wouldn't mind having the legend symbol be a filled-in circle as
well. Is this possible in ggplot2? I'll use the development version if
needed: the previous version of this project I did in lattice, and I
like to move to ggplot2, but I'm required to keep consistent-looking
graphs.
Thanks,
Gregory
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
More options: http://groups.google.com/group/ggplot2
Kohske Takahashi
2011-08-15 00:07:20 UTC
Permalink
hi,

using dev version and Dennis's sample, you can remove the line and set
alpha of legend to 1.0 like this:

dd <- data.frame(gp = factor(rep(1:5, each = 100)), y = rnorm(500))
ggplot(dd, aes(x = y, fill = gp, colour = gp)) +
theme_bw() +
geom_density(alpha = 0.3) +
guides(fill=guide_legend(set.aes=list(colour=NULL, alpha=1)))

find how to install here: https://gist.github.com/1139848


--
Kohske Takahashi <takahashi.kohske-***@public.gmane.org>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html
Post by Dennis Murphy
dd <- data.frame(gp = factor(rep(1:5, each = 100)), y = rnorm(500))
ggplot(dd, aes(x = y, fill = gp, colour = gp)) +
  theme_bw() +
  geom_density(alpha = 0.3)  +
  scale_colour_manual(breaks = levels(dd$gp), values = NA)
The last line of code removes the outlines from the legend but also
from the plot. The alpha transparency is to avoid (partial) obscurity
of one density plot by another.
HTH,
Dennis
Post by Gregory
Hello,
I'm creating a single graph with 5 overlapping density plots. Each is
given its own color through the "colour" parameter in aes(). The
resulting legend is a square box with a 45 degree line through it in
the corresponding colors. I would like, however, for the box to be
fully fill in, rather than just have a thin 45 degree line through it.
I wouldn't mind having the legend symbol be a filled-in circle as
well. Is this possible in ggplot2? I'll use the development version if
needed: the previous version of this project I did in lattice, and I
like to move to ggplot2, but I'm required to keep consistent-looking
graphs.
Thanks,
Gregory
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
More options: http://groups.google.com/group/ggplot2
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
More options: http://groups.google.com/group/ggplot2
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggplot2-/***@public.gmane.org
To unsubscribe: email ggplot2+unsubscribe-/***@public.gmane.org
More options: http://groups.google.com/group/ggplot2
Loading...