Violin Plot

Learn how to build violin plots using ggplot2.

Getting started with violin plots

A violin plot is a combination of a boxplot and a density plot, and it shows the distribution of numerical data. Unlike boxplots, which display only summary statistics, violin plots provide summary statistics and the density of each variable.

Press + to interact
Structure of a violin plot
Structure of a violin plot

Let’s study the structure of the violin plot:

  • The white circle in the center of the violin plot represents the median.
  • The length of the box, i.e., the dark green bar, shows the Interquartile range (IQR).
  • The area surrounding the boxplot displays the estimated kernel densityKernel density estimation (KDE) is a mathematical technique for estimating the probability density function of a given random variable. It is a method for creating a smooth curve for the given dataset. to display the data distribution.

In violin plots, the broader areas indicate a higher probability, while the skinnier sections indicate a lower probability. It also summarizes the data using five summary values:

  • The minimum
  • The maximum
  • The median
  • The first and third quartiles

We will use the warpbreaks dataset, which comprises of 5454 observations on the ...