About this example
Snee (1974) recorded the hair and eye colour of 592 statistics students; R ships the counts as datasets::HairEyeColor, split by sex. Summed over sex, the four hair groups are very different in size, from 71 red-haired to 286 brown-haired students, so raw stacked counts would mostly show group size.
Scaling every bar to 100% puts the groups on the same footing: 74% of blond students have blue eyes, while 63% of black-haired students have brown eyes. Each segment is the count divided by its row total, exactly as prop.table(x, 1) in R; the n at the end of each bar keeps the denominators visible.
Percent labels are rounded for reading, so a row may show 99% or 101% in total while the bar lengths stay exact. Segments under 5% are left unlabelled; the plotted-value table and CSV give every share to full precision.
Sources: R datasets::HairEyeColor — Snee (1974)
The data
| Hair colour | Brown | Blue | Hazel | Green |
|---|---|---|---|---|
| Black | 68 | 20 | 15 | 5 |
| Brown | 119 | 84 | 54 | 29 |
| Red | 26 | 17 | 14 | 14 |
| Blond | 7 | 94 | 10 | 16 |
Supplied counts per answer level. Each bar shows its row’s shares of 100%; no weighting or test. Open the example, replace the data with your own, and export the figure as SVG, PDF, PNG or TIFF.