Skip to content

Instantly share code, notes, and snippets.

@GuangchuangYu
Created February 8, 2012 03:51
Show Gist options
  • Save GuangchuangYu/1765193 to your computer and use it in GitHub Desktop.
Save GuangchuangYu/1765193 to your computer and use it in GitHub Desktop.
generate violin plot using ggplot2
p <- ggplot(mtcars, aes(factor(cyl),mpg,
fill=factor(cyl),
colour=factor(cyl)))
p1 <- p+geom_violin(alpha=0.3, width=0.5) +
geom_boxplot(width=0.2, outlier.colour=NA)
p2 <- p+geom_violin(alpha=0.3, width=0.5) +
geom_dotplot(binaxis='y', stackdir='center', dotsize=0.5)
grid.arrange(p1,p2, ncol=2)
@GuangchuangYu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment