liveBook · Manning

Violin plot

As explained in Statistics Slam Dunk

A violin plot displays the distribution and shape of numeric data by combining a mirrored probability-density shape with optional summary statistics.

A violin plot combines a boxplot with a density plot to show both the distribution and shape of numeric data. Wider regions indicate more frequent values; tapered regions indicate fewer observations. section 15.3.1 section 15.3.3

A violin plot can show several views of the same variable at once:

  • The mirrored density shape displays the full distribution rather than only summary statistics. section 15.3.3
  • An embedded boxplot retains the interquartile range, quartiles, median, and outliers. section 15.3.1
  • A solid point can mark the mean, making mean–median differences useful for spotting skewness. section 15.3.1 section 15.3.3

NBA franchise games and wins

Using records for current and past NBA franchises from 1946–2020, filter out parent records and create two ggpubr plots: one for games played and one for games won. Both distributions are right-skewed: their widest regions lie near zero, while their means exceed their medians. section 15.2 section 15.3.3

p2 <- ggviolin(df2, y = "games",
              color = "darkslategray1", fill = "salmon1",
              add = "boxplot", add.params = list(fill = "white"),
              main = "Distribution of Games Played:\nAll NBA Franchises",
              font.main = "bold",
              subtitle = "1946-2020", 
              xlab = "", 
              ylab = "Games Played") +
 stat_summary(fun = mean, geom = "point", shape = 20, size = 8, 
              color = "darkslategray1", fill = "darkslategray1") + 
 theme(axis.text.x = element_blank())

p3 <- ggviolin(df2, y = "wins",
              color = "darkslategray1", fill = "salmon1",
              add = "boxplot", add.params = list(fill = "white"),
              main = "Distribution of Games Won:\nAll NBA Franchises",
              font.main = "bold",
              subtitle = "1946-2020", 
              xlab = "", 
              ylab = "Games Won") +
 stat_summary(fun = mean, geom = "point", shape = 20, size = 8, 
              color = "darkslategray1", fill = "darkslategray1") + 
 theme(axis.text.x = element_blank())

Inspect executable ggviolin() code that adds embedded boxplots, mean points, labels, and styling for games and wins. section 15.3.1

How Statistics Slam Dunk covers it

How deep it goes
Explains density shape, embedded summaries, and skewness, then demonstrates ggpubr construction without developing the density calculation itself.
Examples
Demonstrates games played and games won for current and past NBA franchises from 1946 through 2020.
What it assumes
Assumes numeric variables and basic R data preparation, while introducing ggpubr violin-plot syntax and interpretation.
What you can do after
Builds distribution graphics in R with ggpubr, adds boxplots and mean markers, and interprets density shape and skewness.
How it connects
Connects violin plots with boxplots, density plots, probability density functions, histograms, and skewness.

Also explained in

Compare how 3 books explain violin plot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.