violin-plot

Split violin plot with ggplot2

自古美人都是妖i 提交于 2019-11-26 14:24:21
I'd like to create a split violin density plot using ggplot, like the fourth example on this page of the seaborn documentation. Here is some data: set.seed(20160229) my_data = data.frame( y=c(rnorm(1000), rnorm(1000, 0.5), rnorm(1000, 1), rnorm(1000, 1.5)), x=c(rep('a', 2000), rep('b', 2000)), m=c(rep('i', 1000), rep('j', 2000), rep('i', 1000)) ) I can plot dodged violins like this: library('ggplot2') ggplot(my_data, aes(x, y, fill=m)) + geom_violin() But it's hard to visually compare the widths at different points in the side-by-side distributions. I haven't been able to find any examples of