What a Stacked Bar Chart Shows
When data record two categorical variables for the same individuals, a chart can show how the categories of one variable are distributed across the categories of the other. A stacked bar chart for counts does this by assigning one bar to each group of the first variable and dividing that bar into segments for the categories of the second. Segment lengths represent counts, and the full bar height represents the group total.
For example, a campus survey might classify each student by residence (on campus or off campus) and usual travel mode (walking, bus, or car). A two-way count table gives the number of students in every residence-by-mode combination. Each residence group becomes a bar, and the counts for its travel modes are stacked to make that bar.
A clear chart needs a title that identifies both variables, labels for the group categories and the counted categories, and a count axis with a common scale starting at zero. Use the same segment order in every bar and distinguish segments with a legend or direct labels. If the counts are small enough, labels inside the segments can make exact values easier to read.
Unlike a clustered bar chart, in which categories are placed side by side within each group, a stacked chart places them on top of one another. The shared baseline makes the first segment in each bar straightforward to compare. For a segment higher in the stack, its position begins where the segment below it ends; its count is the difference between its upper and lower boundaries. Direct labels help avoid estimating that difference from the axis.
From a Count Table to Stacked Bars
Start with the counts for every combination of the two categorical variables. For each group, the counts of its segments add to the group total. In a chart, each segment’s height must correspond to its count using the same scale as every other segment. The segment heights therefore add to the height of the full bar.
Assign one bar to each category of this variable, such as residence or treatment group.
Use the categories of the second variable. Keep their order consistent in every bar and explain the colors or patterns.
Use a common vertical or horizontal axis beginning at zero. Choose a scale that accommodates the largest group total.
Make each segment proportional to its count. The full bar ends at the sum of that group’s segment counts.
Add a descriptive title, axis labels, group labels, and a legend or direct category labels. Include segment counts when exact reading matters.
Worked Example: Building a Chart for Travel Modes
Suppose a hypothetical campus survey records the usual travel mode of 60 students. The two-way count table is:
| Residence | Walking | Bus | Car | Group total |
|---|---|---|---|---|
| On campus | 18 | 9 | 5 | 32 |
| Off campus | 6 | 14 | 8 | 28 |
| Total | 24 | 23 | 13 | 60 |
First check the totals: \(18+9+5=32\) students live on campus, and \(6+14+8=28\) live off campus. The complete count is \(32+28=60\), matching the sum of the travel-mode counts, \(24+23+13=60\).
To construct the chart, put residence on the horizontal axis and student count on the vertical axis. Use a scale from zero to at least 32. In each bar, stack walking at the bottom, bus above walking, and car at the top. For the on-campus bar, the walking segment extends from 0 to 18, the bus segment from 18 to \(18+9=27\), and the car segment from 27 to \(27+5=32\). For the off-campus bar, the corresponding boundaries are 0, 6, 20, and 28. Label the segments or provide a clear legend.
The full bar heights show that the on-campus group has 32 students and the off-campus group has 28. The walking segments show counts of 18 and 6, respectively. To compare the share of each group that walks, compare each walking count with its own bar total: \(18/32=0.5625\), or 56.25%, on campus, and \(6/28\approx0.2143\), or 21.43%, off campus. Thus, among the students surveyed, the walking share is greater for the on-campus group. The chart supplies both counts and group totals, so this comparison can be calculated from it; the raw counts alone would not express the shares.
Reading Segment Counts and Group Totals
A segment answers a count question: how many individuals in this group fall into this category? The complete bar answers a different question: how many individuals are in the group, across all segment categories? Keeping these questions separate prevents a common interpretation error. The largest segment count and the largest within-group share need not belong to the same group when group totals differ.
The relationship is direct. If group \(j\) has counts \(c_{j1},c_{j2},\ldots,c_{jk}\) in its \(k\) categories, then its total is the sum of its segment counts:
Here, \(n_j\) is the height of bar \(j\), and \(c_{ji}\) is the count represented by segment \(i\) in that bar. This sum explains why the bar’s full height represents the group total: each individual in the group belongs to exactly one of the displayed categories, so adding the category counts counts every individual in the group once.
A segment above the bottom of the bar may not start at zero, but its count is still represented by its length. If the lower boundary is at count \(a\) and the upper boundary is at count \(b\), then the segment count is \(b-a\). For exact comparisons, segment labels are often more reliable than visually estimating lengths, especially for segments that lack a common baseline.
Worked Example: Reading Segment Counts and Totals
Imagine a hypothetical student survey that records whether students prefer a quiet or social study space and whether they live in a residence hall or commute. The counts are:
| Group | Quiet space | Social space | Group total |
|---|---|---|---|
| Residence hall | 12 | 8 | 20 |
| Commuter | 9 | 15 | 24 |
| Total | 21 | 23 | 44 |
For residence-hall students, the full bar has height \(12+8=20\). If quiet space is stacked at the bottom, that segment runs from 0 to 12; the social-space segment runs from 12 to 20 and has length \(20-12=8\). For commuters, the bar has height \(9+15=24\): quiet space runs from 0 to 9, and social space runs from 9 to 24, so its length is \(24-9=15\).
The chart shows 12 residence-hall students and 9 commuters in the quiet-space category. It also shows group totals of 20 and 24. The counts answer how many students were recorded in each combination; the total bar heights answer how many students were recorded in each group. Those are distinct pieces of information, even though both come from the same bars.
Unequal Group Sizes Complicate Comparisons
A stacked count chart makes counts visible, but a larger count does not automatically mean a larger share of a group. If one bar represents many more individuals than another, its segment counts may be larger simply because the whole group is larger. For comparisons about who is more likely to be in a category within the surveyed groups, compare each segment count to its own group total. This is a calculation using the chart’s counts and totals, not a reason to compare the segment heights by themselves.
The counts describe the individuals represented in the table. Extending a comparison to a wider population requires an appropriate study design and assumptions; a chart alone does not establish that a sample represents a population or that a difference has a particular cause. Use careful language such as “in these surveyed groups” unless there is a basis for a broader claim.
Worked Example: A Larger Count Does Not Mean a Larger Share
Suppose a hypothetical survey records whether participants chose option A in two groups of different sizes:
| Group | Option A | Option B | Group total |
|---|---|---|---|
| Small group | 12 | 8 | 20 |
| Large group | 32 | 48 | 80 |
| Total | 44 | 56 | 100 |
In the stacked count chart, the option A segment is taller for the large group: 32 compared with 12. But the group totals differ substantially. The option A share is \(12/20=0.60\), or 60%, in the small group, and \(32/80=0.40\), or 40%, in the large group. Thus, the small group has the greater option A share among the surveyed participants, even though its option A count is smaller.
The chart correctly represents the counts and allows the group totals to be read. The mistake would be to conclude from the taller option A segment alone that option A was more common within the large group. To answer a within-group comparison, use each segment count with its own bar total.
Why the Display Matters
Stacked bars combine two useful views: the size of each group and the counts making up that group. They are especially useful when seeing the total number of observations per group is important. They also preserve the category counts, so readers can recover the data when counts or a clear scale are provided.
There is a visual trade-off. The bottom segment of each bar shares a baseline, but the other segments begin at different heights. For example, comparing two middle segments by their top edges alone is not a valid comparison of their counts; their lower boundaries also matter. Labels or the original count table can make such comparisons more precise. If the main goal is to compare within-group shares, a count chart may require readers to calculate those shares from the segment counts and bar totals. A chart that scales each bar to the same total is a different display and is treated separately.
Common Mistakes
- Reading the full bar as one category count. The full height is the group total, not the count in the top segment. Read a segment’s count from its own length or label.
- Comparing counts as if group sizes were equal. A taller segment may reflect a larger group. For a within-group comparison, divide each segment count by its own bar total.
- Using inconsistent segment order. If colors change meaning between bars, the chart is difficult to read and can invite incorrect comparisons. Keep the order and legend consistent.
- Estimating a segment from its upper boundary alone. A segment’s count is its upper boundary minus its lower boundary. Use a label or table when exact counts matter.
- Claiming a population difference from a chart of surveyed counts alone. The chart summarizes the observations shown. Broader conclusions require suitable evidence and assumptions about how the data were collected.
Check Your Understanding
Try these questions using the ideas in this tutorial.
- A group’s stacked bar has segment counts 7, 11, and 4. What is the group total, and how does the bar show it?
- In a stacked bar, a segment extends from the count-axis value 15 to 23. What count does that segment represent?
- Two groups have counts of 14 and 20 in the same category, with group totals of 20 and 50. Which group has the larger count? Which has the larger within-group share?
- Why should the segment order and color meanings stay consistent across bars?
- What does a stacked count chart show that cannot be concluded from raw segment heights alone when group sizes differ?