Descriptive statistics

100% stacked bar chart: eye colour by hair colour

100% stacked bar chart of eye colour within each hair colour for 592 students (R HairEyeColor), with percent labels and n per bar.

Open this example in the editorStart from scratch

BrownBlueHazelGreen0%25%50%75%100%63%19%14%42%29%19%10%37%24%20%20%6%74%8%13%n10828671127BlackBrownRedBlondEye colour (%)Hair colour
Eye colour as a share of each hair colour group (n = 108, 286, 71 and 127); labels are rounded percents.

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 colourBrownBlueHazelGreen
Black6820155
Brown119845429
Red26171414
Blond7941016

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.

More examples