liveBook · Manning

Stacked bar chart

As explained in Data Storytelling with Altair and AI

A stacked bar chart displays categorical quantities as segments within bars so component values form a total.

A stacked bar chart displays categorical quantities as segments within bars, allowing component values to form a total. It can turn raw counts or percentages into an immediately readable comparison. section 1.4.1

Use one when the audience needs to understand how parts contribute to a whole. A clear chart should expose the intended insight rather than merely display every available category. section 1.4.1

Build the chart progressively:

  • Check scale and ordering before presenting the result. Large differences between variables can make a stacked chart narrow, unclear, and difficult to interpret. section 4.5.1

Pets at an event

A participation table contains 1,138 cats, 130 dogs, and 17 other pets. Focusing on the relevant categories gives approximately 90% cats and 10% dogs, or one dog for every nine cats. A stacked percentage bar communicates that relationship at a glance. section 1.4.1

Training-time comparison

For competition data, reshape Record Time and Our Best Time into stacked series with Altair. If their scales obscure the comparison, calculate percentage difference instead, sort categories descending, and constrain the y-scale to 0–100.

How Data Storytelling with Altair and AI covers it

How deep it goes
Explains category selection, percentage calculation, reshaping, encodings, and scale limitations, but defers deeper visualization theory.
Examples
Uses pet participation percentages and competition times reshaped into stacked series as concrete charting examples.
What it assumes
Assumes tabular data and basic categorical comparison, while demonstrating pandas loading and reshaping from the data-processing stage.
What you can do after
Builds a stacked bar chart from tabular data and revises the design when scale differences prevent effective comparison.
How it connects
Connects stacked bar charts with data storytelling, bar charts, percentage difference, pandas, Altair, and data transformation.

Also explained in

Compare how 5 books explain stacked bar chart →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.