BoxPlot uses the Tukey 1.5×IQR rule for whiskers, making outliers easy to spot. Individual data points can be overlaid as jittered strips or beeswarms.
When to Use
- Comparing distributions across multiple groups
- Quickly assessing center, spread, and skewness
- Identifying outliers
- Visualizing experimental conditions side-by-side
- Showing quartile-based summaries when you don’t need full density
Basic Example
Key Methods
Data Input
Add a group (one box) with a label and raw values:Groups are rendered left-to-right in the order they are added. The renderer computes Q1, median, Q3, and Tukey whiskers from the supplied values.
Styling
Set the box fill color:This color is applied to all boxes. To use different colors per group, create multiple
BoxPlot instances and layer them.Set box width as a fraction of the category slot (default
0.8):Overlays
Overlay individual data points as a jittered strip:
jitter controls the horizontal spread. A value of 0.2 spreads points ±20% of the category width. Use a semi-transparent color with .with_overlay_color() so the box remains visible.Overlay individual points as a beeswarm (non-overlapping layout):Points are spread horizontally to avoid overlap, clearly revealing density. Works best for N < ~200 per group.
Set the fill color for overlay points (default
"rgba(0,0,0,0.45)"):Set the radius of overlay points in pixels (default
3.0):Legend
Attach a legend label:
Examples
Basic Box Plot
Box Plot with Strip Overlay
Box Plot with Swarm Overlay
Multiple Box Plots with Different Colors
Understanding Box Plots
Five-Number Summary
- Box bottom edge: Q1 (25th percentile)
- Line inside box: Median (Q2, 50th percentile)
- Box top edge: Q3 (75th percentile)
- Box height: IQR (Interquartile Range = Q3 - Q1)
- Whiskers: Tukey 1.5×IQR rule
Whisker Calculation
Kuva uses the Tukey method:- Lower whisker: Extends to the smallest value ≥ Q1 - 1.5×IQR
- Upper whisker: Extends to the largest value ≤ Q3 + 1.5×IQR
- Outliers: Values beyond the whiskers (not automatically plotted; use overlays to show all points)
Reading Box Plots
- Center: Median line shows typical value
- Spread: Box height (IQR) shows middle 50% of data
- Skewness: Asymmetric box or whiskers indicate skew
- Outliers: Points beyond whiskers are unusual values
Tips
Whiskers do not show min/max in Kuva; they use the Tukey 1.5×IQR rule. Values beyond the whiskers exist but aren’t plotted by default.
Alternatives
- Violin plots - Show full density estimate; reveal multimodality and distribution shape
- Strip plots - Show every individual point without summarization
- Histograms - More detail for single distributions
Source Location
Implementation:src/plot/boxplot.rsExamples:
examples/boxplot.rs