Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Faceted density

A composition pattern, not a separate value type. Render one KDE per facet (category, time window, group) inside the trellis small-multiples layout — same data shape, repeated per facet.

The single-facet demo below reuses the KDE chapter's Civil War recruit-height dataset (Gould 1869). A genuine faceted build would render one panel per recruit-age bracket (e.g. 18-21 / 22-25 / 26-29 / 30-34) so the reader could compare the distribution shape across cohorts at a glance.

Source: Anthropometric history — Wikipedia

Pattern

use wisp_chart::distributions::KdePlot;
use wisp_chart::multi::Trellis;

let facets: Vec<KdePlot> = groups
    .iter()
    .map(|group| KdePlot::new(group.samples.clone()))
    .collect();

let trellis = Trellis::new(facets, /* cols */ 3, /* gap_px */ 16.0);
let g = trellis.emit_graphics(&theme, viewport);

Why faceted instead of overlaid

Overlaying many KDEs on one axis is legible up to ~5 series. Past that, the eye loses which curve is which even with distinct colours. Faceting trades axis-comparison ease for "each facet reads cleanly" — the right choice for >5 groups.

Picking facet count

If n series fit in cols × ⌈n/cols⌉ facets with cols ≈ √n, the aspect ratio of the grid stays close to 1:1. The trellis chapter has the full layout recipe.