The following data set contains the effect of vitamin C on Tooth Growth. The dose
column has been converted into a factor to be used as the categorical variable.
Option 1
The points can be added over a violin plot with geom_point
. However, it is recommended to add some jitter with position_jitter
, where seed
is the pseurodandom number generator seed (optional) and width
is the jittering width.
Option 2
You can get the same result using geom_jitter
function.
If you want to create a violin plot with dots in ggplot2 you can use geom_dotplot
, setting binaxis = "y"
and stackdir = "center"
. Note that dotsize
controls the size of the points.
The default dots are of the same color of the groups. To override this you can specify a fill color inside geom_dotplot
.
An alternative for adding data points over a violin plot in ggplot is using the geom_beeswarm
function from ggbeeswarm
library.
The ggbeeswarm
package also contains a function named geom_quasirandom
, which can be used to add the points inside the violins, as you can see in the example below.
See also