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

Scatterplot

Two continuous numeric variables plotted as points — correlation explorations, A/B comparisons, sample distributions. Categorical colour and varying size for richer reads.

The demo plots Fisher's Iris (1936): petal length × petal width across the three species setosa, versicolor, and virginica. R.A. Fisher published this dataset in The Use of Multiple Measurements in Taxonomic Problems to demonstrate linear discriminant analysis; it has since anchored statistical classification, machine-learning tutorials, and 90 years of shape-from-petal arguments.

Source: Iris flower data set — Wikipedia

Public surface

let plot = Plot::new(samples)
    .mark(Mark::Point { shape: PointShape::Circle })
    .encode(plot::x("height", ScaleKind::Linear))
    .encode(plot::y("weight", ScaleKind::Linear))
    .encode(plot::color("species"))
    .encode(plot::size("age"));

Point shapes

ShapePrimitive used
CircleGraphics::draw_ellipse
SquareGraphics::draw_rect
DiamondGraphics::draw_polygon (4 verts)
TriangleGraphics::draw_polygon (3 verts)
PlusTwo crossed draw_rect calls

Info

Both X and Y must use ScaleKind::Linear — scatter requires continuous numeric axes. Categorical X is the domain of bar charts.

Size encoding

Adding plot::size(field) maps a numeric column to marker radius via LinearScale mapped into (3.0, 18.0) pixel range. Use sparingly — too many sizes overlap and obscure the distribution shape.

Theme integration

Theme fieldDrives
theme.plot.line_marker_radius_pxDefault marker radius (no Size)
theme.palettePer-category fill colour