side-by-side vertical density plots

476 views
Skip to first unread message

Alexander Shenkin

unread,
Sep 18, 2012, 10:58:40 AM9/18/12
to ggp...@googlegroups.com
Hello all,

I'm trying to make vertical density plots of the type found here: http://had.co.nz/ggplot2/stat_density.html  (and see below for the clip).  However, I'm trying to put two vertical bars side by side in each facet_grid category.  So, for example, below I would like to have two vertical bars in the "Fair" category - one bar for one data group, and another bar for another.  The same for "Good", "Very Good", etc.

Any ideas about how I might go about doing that?

Thanks!

Alex


Brandon Hurr

unread,
Sep 18, 2012, 11:30:27 AM9/18/12
to Alexander Shenkin, ggp...@googlegroups.com
?facet_wrap

ncol=2

might work

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

afhjjfee.png

Dennis Murphy

unread,
Sep 18, 2012, 1:10:51 PM9/18/12
to Alexander Shenkin, ggp...@googlegroups.com
Hi:

On Tue, Sep 18, 2012 at 7:58 AM, Alexander Shenkin <ashe...@ufl.edu> wrote:
Hello all,

I'm trying to make vertical density plots of the type found here: http://had.co.nz/ggplot2/stat_density.html  (and see below for the clip).  However, I'm trying to put two vertical bars side by side in each facet_grid category.  So, for example, below I would like to have two vertical bars in the "Fair" category - one bar for one data group, and another bar for another.  The same for "Good", "Very Good", etc.

Winston Chang developed geom_violin() to generalize this type of plot, so for your example below, this would work in versions of ggplot2 >= 0.9.0:

library('ggplot2')
library('scales')
ggplot(diamonds, aes(x = cut, y = price)) + geom_violin()  # default
# variant
ggplot(diamonds, aes(x = cut, y = price)) + theme_bw() +
   geom_violin(fill = "grey50") +
   scale_y_continuous(labels = dollar)

Do you want separate sets of violin plots by a levels of a third (factor) variable or to superimpose dodged bar plots wrt a third variable on top of the violins? If the latter, what are the values that are supposed to represent the heights of the bars? A reproducible example apropos to your goals would be useful.

Dennis

Any ideas about how I might go about doing that?

Thanks!

Alex


--
afhjjfee.png

Alexander Shenkin

unread,
Sep 18, 2012, 4:23:01 PM9/18/12
to Dennis Murphy, ggp...@googlegroups.com
Thanks all!

geom_violin(fill = factor(var)) did the trick.  thanks!

allie
Reply all
Reply to author
Forward
0 new messages