parameter to change total area in geom_violin()?

2,304 views
Skip to first unread message

Alexander Shenkin

unread,
Dec 1, 2013, 3:48:20 PM12/1/13
to ggplot2
Hi Folks,

Is there any way to make geom_violin() produce violins with larger or
smaller total areas? I have some plots but would like to make their
areas fatter (while still keeping total areas of different violins equal).

Thanks,
Allie

Alexander Shenkin

unread,
Dec 2, 2013, 4:19:37 PM12/2/13
to ggplot2
Just wanted to follow up with an example:

df = data.frame(y = c(rnorm(200)*30, rnorm(100)), x = factor(c(rep(c("class1","class2","class3","class4","class5"),length.out=200),rep("class6",100))))
ggplot(data=df, aes(x = x, y = y)) + geom_violin()



It seems that geom_violin scales the areas of each shape such that the width of the widest violin is a constant.  In the case above, this scaling makes the thinner violins difficult to interpret.  It would be nice to be able to modify that maximum width such that the total areas of each shape is increased, and all shapes become a bit fatter as a result.

Any thoughts?

Thanks,
allie

Ista Zahn

unread,
Dec 2, 2013, 10:22:03 PM12/2/13
to Alexander Shenkin, ggplot2
You can change the width, e.g.,

ggplot(data=df, aes(x = x, y = y)) + geom_violin(width = 2)

but the distributions are so different that the basic issue is still there. If your real data is less extreme than your example this might be enough.

Best,
Ista 


--
--
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
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

hbebcbac.png

Alexander Shenkin

unread,
Dec 3, 2013, 10:40:19 AM12/3/13
to Ista Zahn, ggplot2
Hmm, "width".  Why didn't they choose something that made sense?  ;-)

Thanks Ista.  I was about to say, "I wonder why I didn't figure that out before," but then I realized that the "width" argument isn't in geom_violin's help blurb.  Perhaps it should be put in?  Or, is there a standard set of arguments that don't get explicitly put in the help files?

Best,
Allie

Ista Zahn

unread,
Dec 3, 2013, 10:46:52 AM12/3/13
to Alexander Shenkin, ggplot2
Good question, I don't know where this is documented. I think I learned about width from the geom_bar example, but I don't see it actually described anywhere...

Best,
Ista
Reply all
Reply to author
Forward
0 new messages