How do I draw a violin plot using ggplot2? - r

Can I use ggplot2 to produce a violin plot? Perhaps using some variation of geom_boxplot()?

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.

Related

Is it possible to set a theme with plotly in R?

plot_ly(x,y,z, type="scatter3d") + theme_igray()
Returns NULL. Is it possible at all to have theme with plotly?
The theme_igray() call looks like something from ggplot2. I don't think the plotly package supports ggplot2 themes, but ggplotly can convert a ggplot2 graph to plotly format, so you could theme it in ggplot2 then convert.
Unfortunately, there's no ggplot2 graph that corresponds to type="scatter3d". The gg3D package will produce a 2D graph in plotly.

Modify `geom_violin` to plot a histogram instead of a density?

Would it be possible to extend geom_violon (and ideally geom_split_violin as in #jan-glx's answer here Split violin plot with ggplot2)?
How would I go about doing this?

Combined ggplot and plotrix

I need to add a Y axis break to a plot I made in ggplot. Is it possible to use the gap.barplot function in plotrix in a graph in ggplot? When I try, it cancels everything I did in ggplot and plots just the gap.barplot bit.
Thank you
Barbara
Unfortunately NO.
They work on two different "worlds".
I've been trying a lot but it seems (just like #Mark Peterson wrote) that doing this in ggplot is nearly impossible on purpose
You should look into these questions and answers which are very similiar:
Using ggplot2, can I insert a break in the axis?
Broken barplot using R/ggplot2

Stacked dot plot using ggplot2

I am interested in making a stacked dotplot like the one in link below in ggplot2.
The following was made using dotPlot function in BHH2 package but does not have the coloring and faceting ease of ggplot2.
There is a geom_dotplot which create dotplots. Update your ggplot2 if you don't have it. It is a relatively recent addition.
See this for examples.

How does one plot a 3D stacked histogram in R?

I want to plot stacked histograms in R; i.e. stack individual histograms in the third dimension.
thank you all for your suggestions, especially the one by Shane.
#hadley, I agree with your points, however, my situation is different: the main point I'm trying to convey by plotting four stacked histograms is that the tails vary significantly....the part that will get obscured is of no consequence in the data I'm presenting....also, being able to read the frequency axis is also not important since I'll be plotting the relative frequencies...
One doesn't. This is a terrible display of data because the front histograms obscure the rear histograms and the perspective makes it just about impossible to read the values off the y-axis.
You could try using either rgl (see here) or 3dscatterplot (as in this example). Lattice also supports this:
library(lattice)
library(latticeExtra)
?panel.3dbars
You can see an example of this on the Learnr blog.
I don't believe that's technically a stacked histogram (a stacked histogram stacks the bars on top of each other). Moreover, a different kind of histogram could be more informative: look at the ggplot2 the documentation here for some examples.
hist_cut <- ggplot(diamonds, aes(x=price, fill=cut))
hist_cut + geom_bar() # defaults to stacking
Another option is to use latticing instead, with facet_wrap in ggplot2 (see this post as an example).

Resources