Distribution CategoricalNumerical
Violin Plot
ggplot2: geom_violin() · Package: ggplot2 · Variables: 1 numerical + 0-1 categorical
WHAT IS A VIOLIN PLOT?
A violin plot combines a box plot with a mirrored kernel density curve, revealing the full shape of the distribution — not just its summary statistics. It answers "what does the distribution actually look like?" and is especially valuable for detecting bimodal or multimodal distributions that box plots would hide. Common practice is to overlay a slim box plot inside the violin for the five-number summary. In ggplot2, use geom_violin() optionally combined with geom_boxplot(width = 0.1).
BEST FOR
- · When distribution shape matters
- · Detecting bimodality
- · Richer alternative to box plot
AVOID WHEN
- · Very small samples
- · Non-technical audience
- · Too many groups (10+)
R + GGPLOT2 CODE EXAMPLE
ggplot2
ggplot(mtcars, aes(x = factor(cyl), y = mpg)) + geom_violin(fill = "#ff6a00", alpha = 0.7) + geom_boxplot(width = 0.1) + labs(title = "MPG Distribution by Cylinders", x = "Cylinders", y = "MPG")
Run this code now
Paste the code above into RChat and see the violin plot rendered instantly in your browser.
SIMILAR CHART TYPES
Histogram geom_histogram()
Frequency distribution of a continuous variable grouped into bins, showing distribution shape.Density Plot geom_density()
Smoothed continuous curve estimating the probability distribution of a variable.Box Plot geom_boxplot()
Shows median, quartiles, range, and outliers as a compact distribution summary.Ridgeline Plot geom_density_ridges()
Stacked overlapping density plots showing distribution changes across groups.ALTERNATIVES FOR YOUR DATA TYPE
Bar Chart Comparison, Ranking
Compares values across discrete categories using rectangular bars proportional to values.Horizontal Bar Chart Comparison, Ranking
Horizontal bars ideal for long labels, many categories, or ranked/sorted data.Grouped Bar Chart Comparison
Clusters of bars comparing sub-groups within each category side by side.