Can I use ggplot2
to produce a violin plot? Perhaps using some variation of geom_boxplot()
?
How do you make a violin plot in R? To make a violin plot in R you can use ggplot2 and the geom_violin() function. For example, if we have the dataframe dataF and want to create a violin plot of the two groups response times you can use the following code: <code>p <- ggplot(aes(Group, RT), data = dataF))</code>.
The function stat_summary() can be used to add mean/median points and more on a violin plot.
A violin plot is more informative than a plain box plot. While a box plot only shows summary statistics such as mean/median and interquartile ranges, the violin plot shows the full distribution of the data. The difference is particularly useful when the data distribution is multimodal (more than one peak).
Version 0.9.0 includes the geom_violin
: http://docs.ggplot2.org/current/geom_violin.html
A quick googling returns this site, which uses geom_ribbon to draw violin plots for Figure 3.14.
Note to anyone catching up
As @Ben points out below, geom_violin() is now the preferred method for producing violin plots in ggplot2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With