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


