4.5.2 Violin plot
Last updated
Last updated
A violin plot is a method of plotting numeric data. It is similar to a box plot, with the addition of a rotated kernel density plot on each side. Violin plots are similar to box plots, except that they also show the probability density of the data at different values, usually smoothed by a kernel density estimator.
However, the violin plots can be harder to read and it not commonly used in professional settings.
Let's use the "mpg" and "tips" datasets for example.
This violin plot shows the relationship of feed type to chick weight. The box plot elements show the median weight for horsebean-fed chicks is lower than for other feed types. The shape of the distribution (extremely skinny on each end and wide in the middle) indicates the weights of sunflower-fed chicks are highly concentrated around the median.
Like horizontal bar charts, horizontal violin plots are ideal for dealing with many categories. Swapping axes gives the category labels more room to breathe.
Violin plots can also illustrate a second-order categorical variable. You can create groups within each category.
Example 1
Example 2