Use absolute and normalized stacks for different questions, and retain every segment count.
Stacked bars: separate composition from volume and preserve denominators
A stack has two possible questions
An absolute stacked bar shows a total and its parts in the same unit. A normalized bar forces every total to one and shows the mix instead. These are not interchangeable. If depot A closes 47 of 81 requests while depot B closes 470 of 810, both have the same closed share, but the latter carries ten times the workload. Place total and share in adjacent views when both matter. Define the denominator before calculating either bar. The title should say whether the horizontal extent means requests or a fraction of eligible requests.
Keep categories stable
Assign each status one color and one position across periods. If a status disappears, retain its zero-valued place in the data contract rather than shifting every later segment. The unanchored middle segments in a stack are difficult to compare precisely; when one category is the focus, use a grouped bar or a separate trend. Sort bars by a declared metric, such as eligible volume, and keep that order fixed across comparison panels. Facet ordering follows the same rule.
Handle absent and ineligible records
A missing status is not necessarily a measured zero. If the warehouse omits unresolved requests, a normalized stack can show an apparently perfect closure rate even as the unobserved group grows. Reconcile segment counts to the cohort total, expose an unknown state, and reserve a separate no-exposure state when the denominator is zero. A percentage bar for zero eligible requests has no defined composition. Missing-state display should use a label or pattern in addition to color.
Audit every filter
When a dashboard filters by region or week, recompute each segment count from the selected cohort and normalize only after filtering. Do not average prior percentages. Tooltips and exports should include segment count, denominator and percentage; rounded shares may sum to 99.9 or 100.1, which is a display effect rather than a data error. Linked selections must update totals and segments together. Test one-bar, zero-cohort and category-absent states before release.
Worked contract
def composition_by_depot(
counts: dict[str, dict[str, int]], statuses: tuple[str, ...]
) -> dict[str, dict[str, tuple[int, float | None]]]:
if len(set(statuses)) != len(statuses) or not statuses:
raise ValueError("statuses must be unique and nonempty")
result = {}
for depot, segments in counts.items():
if set(segments) - set(statuses) or any(value < 0 for value in segments.values()):
raise ValueError("unknown status or negative count")
total = sum(segments.values())
result[depot] = {
status: (segments.get(status, 0),
segments.get(status, 0) / total if total else None)
for status in statuses
}
return result
mix = composition_by_depot(
{"north": {"closed": 47, "pending": 34},
"south": {"closed": 470, "pending": 340}},
("closed", "pending", "unknown"))
assert mix["north"]["closed"] == (47, 47 / 81)
assert mix["south"]["closed"] == (470, 470 / 810)
assert mix["north"]["unknown"] == (0, 0.0)Performance and operating cost
For D depots, S declared statuses and M supplied segment values, validation and construction take O(M + DS) expected time and O(DS) output space. Reusing a prebuilt status set removes repeated set construction in a larger implementation. Rendering a normalized bar still needs the absolute counts for labels and audit. The example treats an absent segment as observed zero only under the stated complete-status contract; without that contract, an absent segment must be marked unknown.
Common Mistakes
- Reading equal-width normalized bars as equal workloads.
- Dropping unresolved statuses before calculating shares.
- Changing stack order between weeks and implying a category moved.
- Averaging percentages instead of adding segment counts first.
Validation drill
Prepare 13 weekly depot bars with different cohort sizes. Show absolute and normalized versions, then remove one status record from a source extract and verify reconciliation fails rather than silently improving a percentage.
Read next
- Aggregation grain and denominator: make every plotted mark auditable
- Small multiples: compare groups with honest scales and facet order
- Interactive dashboards: recompute cohorts after linked filters
- Heatmaps: make missing cells, rates and color domains explicit
Continue this visualization path
- Streamgraphs: preserve totals behind a moving baseline
- Mosaic plots: make cell area match the underlying count
- Ternary plots: preserve the total behind a three-part composition
- Population pyramids: compare age bands without losing the denominator
- Likert diverging stacks: keep the neutral split and response denominator honest
- Waffle charts: allocate whole cells without losing the total
- Sunburst charts: reconcile the leaf ledger before drawing rings
- Marimekko charts: make width, height and area reconcile
