Stacked Bar Chart

Stacked bar chart shows how a total is divided into segments across more than one category. Unlike pie and donut charts, it lets readers compare composition across several groups in one view.

Figure purpose

Use stacked bar when the real question is not only "what parts make up this whole?" but also "how does that composition change from group to group?"

In Licklider, the mapping contract for both variants is long-format:

  • x_column: the category on the horizontal axis (answer keys: group or x)
  • stack_column: the segment within each bar (answer key: stack_column)
  • value_column: the numeric amount summed into each segment (answer keys: value or y)

lib/fig/chart_conditions.json lists required mappings as x_column, stack_column, and value_column, with two categorical roles and one numeric role. In automatic chart selection, stacked bar candidates are gated by min_groups: 2 against the dataset profile's group_profile.n_groups (the same field used for other grouped-chart checks), alongside min_n_per_group: 1.

Rows with the same (x_column, stack_column) pair are aggregated by summing numeric values before rendering (lib/fig/plotHandlers/stackedBar.ts).

Variants

The product wires two chart types to the same builder:

  • stacked_bar: barmode: "stack" with absolute y-values (no barnorm).
  • stacked_bar_100: same stacking, plus Plotly barnorm: "percent" so each bar sums to 100% on the y-axis.

Choose the standard form when total size matters. Choose the 100% form when the comparison is about proportional mix.

Licklider can render either variant, but it does not decide the scientific question for you. The key choice is whether readers need to compare absolute totals or within-group composition; that interpretation decision should be made explicitly rather than inferred from the availability of both chart types.

When to use

Use stacked bar chart when all of the following are true:

  • You need to compare composition across multiple categories
  • You have one categorical grouping for the x-axis and one categorical variable for the stacked segments
  • The number of segments is still small enough that readers can distinguish colors and legend entries

Prefer the 100% variant when:

  • Total counts differ substantially between groups
  • The main message is how the proportions shift, not how large the totals are

Do not use stacked bar chart when:

  • You need precise comparison of interior segment lengths (readers must judge lengths without a common baseline on the same side for middle segments)
  • You have so many segment levels that the legend becomes hard to scan
  • The real question is a direct distribution comparison rather than a composition question

Required columns

Stacked bar chart requires three mapped roles:

  • A categorical x-axis column
  • A categorical stack column
  • A numeric value column

The current renderer assumes long-format data. There is no separate wide-format contract for multiple value columns in this chart family.

What Licklider displays

Implementation details (lib/fig/plotHandlers/stackedBar.ts, lib/fig/figGen/plotDispatch.ts):

  • One Plotly bar trace per distinct stack level; traces are stacked (barmode: "stack").
  • Legend title uses the stack column name; each trace name is the segment label.
  • Standard stacked bar: y-axis title is the value column name.
  • 100% stacked bar: y-axis title is Percentage (%), with barnorm set to percent.
  • Layout title follows the pattern Stacked Bar: <value> by <x> or 100% Stacked Bar: <value> by <x> (using the mapped column names).
  • Rows where the x label, stack label, or numeric value is missing or invalid are skipped (empty labels and non-finite numeric values are dropped).
  • Order of x-axis categories and of segment traces follows first-seen order in the input rows, not a fixed alphabetical sort.

Reading note: the total bar height is easy to compare because it shares a baseline, but interior segment lengths do not. Middle segments are therefore useful for broad composition reading, not for precise length-by-length comparison across bars.

Coloring: segment traces are separate series. When the figure is driven through the IR path with params.color_palette, the same palette cycling used for other multi-trace plots applies (lib/plot/irToPlotly.ts). The initial plot from the generator relies on Plotly default series colors until style overrides exist.

Example

Appropriate use

A flow cytometry experiment reports cell-type composition for each treatment arm. Each row contains treatment arm, cell type, and cell count. Use a standard stacked bar when absolute counts by arm matter. Use a 100% stacked bar when the message is how the cell-type mixture shifts across arms, even if total counts differ.

Inappropriate use

Five biomarkers with mean concentrations 12.1, 13.4, 11.8, 14.2, and 12.9 in the same arbitrary units. The task is to compare those means, not how they add up to a whole. Use a strip plot or box plot.

Alternative figures

  • Use Pie Chart or Donut Chart when you only need composition for a single group.
  • Use Heatmap when both the number of groups and the number of segment levels are large enough that stacked bars become legend-heavy and hard to scan.
  • Use Distribution and Group Comparison when the question is about comparing values or distributions rather than composition.

Design Rationale & References

Stacked bars encode totals with bar length (a high-accuracy channel on a common scale), which is why they are often preferred over pie charts for comparing composition across groups [1]. Interior segments still lack a shared baseline for length comparison, so keep segment counts modest and treat precise segment reading with caution.

See Part to Whole - Design Rationale & References for the full citation list and Licklider's rationale for pie-style figures.

See also