Stacked bar charts

This module should take 30 minutes to complete.

When to use stacked bar charts

Part-to-whole data

Stacked bar charts can be used in lots of situations, but they are particularly useful when you want to compare multiple part-to-whole relationships.

This is because with part-to-whole data, all the bars will be the same length. This makes it easier to compare the size of the stacks within the bars.

Figure 1: Percentage of religious and civil ceremonies for first marriages and remarriages, England and Wales, 2019

The legend follows the same order as the stacks within the bars.

Larger version of figure 1.

This chart shows a stacked bar chart displaying the split between religious and civil ceremonies for:

  • first marriages for both partners
  • remarriages of one partner
  • remarriages of both partners

It shows religious ceremonies are more common in first marriages of both partners.

Source: Marriages in England and Wales from the Office for National Statistics

Part-to-whole data over time

Stacked bar charts can also be a useful way of showing how part-to-whole relationships change over time.

Figure 2: Percentage of people cohabiting and not cohabiting before marriage, opposite-sex marriages, England and Wales, 1999, 2009 and 2019

The legend follows the same order as the stacks in the bars.

Larger version of figure 2.

This stacked bar chart shows that the percentage of people cohabiting before marriage has increased, from just under 75% in 1999 to just under 90% in 2019.

Source: Marriages in England and Wales from the Office for National Statistics

Back to top of page

When not to use stacked bar charts

Stacked bar charts are used frequently and they do give an easy way to show all the data. But, they are not always the best option.

Sometimes the message of the chart gets lost because there is too much information shown in one chart. Remember – you should always start with the message. See our Data visualisation examples (link opens in a new tab) for a discussion about this.

Back to top of page

Considerations for stacked bar charts

Limit to four stacks

Aim for a maximum of four stacks within each bar. If you have more than four the chart can get too cluttered.

Figure 3: Items bought in a shop by three different shoppers, fictional data (eight categories)

Larger version of figure 3.

 

This chart shows a stacked bar chart with eight stacks in each bar. Each stack represents a food. The foods are: apples, pineapples, limes, pints of milk, packets of cheese slices, tubs of butter, sausages and burgers.

The chart is cluttered, hard to read and it is difficult to match labels to categories.

We would normally say “the legend follows the same order as the stacks in each bar” above the chart to assist users who may not be able to differentiate colours. But we cannot say this in this example as there are too many categories.

Combining stacks

One way to solve having more than four categories in a bar is to combine them.

Figure 4: Items bought in a shop by three different shoppers, fictional data (combined categories)

The legend follows the same order as the stacks in each bar.

Larger version of figure 4.

This stacked bar chart shows the data about food items from the previous chart, grouped into broader categories. The categories are: pieces of fruit, dairy products and meat products. This makes the chart simpler and easier to read.

Whether this is an appropriate way to display your data will depend on your data, how it can be grouped and what message you are trying to get across.

Having more than four stacks in a bar is a common problem when presenting data on a Likert scale (often used in survey questions). But responses can be combined and we advise you to do so whenever appropriate.

Further guidance on combining categories in stacked bar charts (link opens in a new tab).

Ranking bars by stacks

If you rank bars by a particular stack, the stack you choose will stand out so consider what you are trying to communicate.

Figure 5: Levels of satisfaction in public institutions, UK, March 2022

The legend follows the same order as the stacks in each bar.

Larger version of figure 5.

This stacked bar chart shows answers to a question about satisfaction in public institutions. The public institutions listed are: the NHS, administrative services, the courts and legal system, the police, the education system and social care services. ‘Satisfied’ has been put as the first stack and the institutions have been ranked by this.

It shows 69% of the UK population reported being satisfied with the NHS (the public service with the highest satisfaction score).

Note 1: Not all bars reach 100% because of rounding

Source: Trust in government, UK, 2022 from the Office for National Statistics

This presentation makes the ‘satisfied’ stack stand out. It is easier to compare this stack across the bars.

Negative values

When stacked bar charts contain negative values it can cause issues.

Figure 6a: Growth rates for three areas of the economy, fictional country, 2005 to 2019 (%)

 

Larger version of figure 6a

This chart shows a stacked bar chart of growth rates for three areas of a fictional economy for each year between 2005 and 2019. Sometimes the growth rates are negative. The chart has a red cross above it.

When there are negative values in a stacked bar chart the order of the stacks changes. This can make it hard to see what the chart is showing.

The chart also fails the accessibility success criterion related to colour contrast. Remember: our categorical colour palette should be used in the order it is presented within our colours guidance. The dark blue and the dark pink should not be next to each other.

Lastly, the chart fails the accessibility success criterion for use of colour. This is because as the stack order changes, the legend does not always stay in the same order as the stacks in the chart. This makes it hard to match labels to stacks.

More information on digital accessibility can be found in earlier modules of this e-learning or in our colours guidance (link opens in a new tab).

For all these reasons, we advise to avoid stacked bar charts when some stacks have negative values. Small multiple charts are better for this type of data.

Figure 6b: Growth rates for three areas of the economy, fictional country, 2005 to 2019 (small multiples)

Larger version of figure 6b.These charts show the growth rates for the three different areas of the economy on three separate bar charts.

It is easier to see the situation in each area and how it compares to the others when the growth rates are presented like this.

Note: you only need the y-axis labels once on each row of small multiple charts, this reduces visual clutter.

Creating and publishing small multiples

Small multiples can be made using basic Microsoft software. They can also be done using open source software like R.

If you publish small multiples as images on a webpage remember to consider the size – they may not be appropriate if they are too small.

Back to top of page

Formatting stacked bar charts

Adjacent colours

The colour contrast ratio between adjacent colours in charts needs to be at least 3 to 1. This includes the contrast of chart elements with the background colour.

This is always possible for categorical data shown in stacked bar charts (when there are no negative values). See the categorical data colour palette in our colours guidance (link opens in a new tab).

But it is not possible when using a sequential palette made up of the same shade (for example the sequential colour palette from our guidance is dark blue, mid blue and light blue).

When using a sequential palette with clustered bar charts we could use an outline around each bar to solve the problems of colour contrast. However, we cannot do this with stacked bar charts as this distorts the size of the stacks within each bar.

This means you should only use a sequential palette in stacked bar charts when essential (see accessibility success criterion 1.4.11 Non-text Contrast).

Quick practice on changing colours of stacks (PPTX, 71KB)

This activity shows you how to change the colour of the stacks in stacked bar charts using Microsoft Office programs.

Please email Analysis.Function@ons.gov.uk if you have any problems accessing or using this file.

Legends

Matching data labels to bars or stacks using colour or shape is problematic for some users who may find it hard to see and/or differentiate between colours and shapes.

This is why legends tend to fail the Web Content Accessibility Guidelines (WCAG). See earlier modules of this e-learning for more information on WCAG.

This means we should try to avoid using legends. When we have to use them we should make them easier to use.

Tips for using legends in stacked bar charts

If possible, instead of using a legend, label the stacks in the first bar directly.

Figure 7: Number of items bought in a shop by three different shoppers, fictional data Larger version of figure 7.

This stacked bar chart shows the numbers of pieces of fruit, dairy products and meat products three shoppers bought in a fictional shop.

There is no legend but each stack in the first bar is labelled.

This presentation means the label is matched to the data series using placement alongside colour. This is more accessible than relying solely on colour.

However, the suitability of this approach depends on the length of your labels.

If they are too long they may not fit or may add a lot of clutter.

If this is the case you may have to use a legend. You should:

  • make sure the legend has the same order and orientation as the stacks
  • state this information in the text that comes directly before the chart

Figure 8: Levels of satisfaction in public institutions, UK, March 2022

The legend is presented in the same order and orientation as the stacks in each bar.

Larger version of figure 8.

This stacked bar chart shows the same data as Figure 5. But this time, instead of looking at the ranking of the bars, notice that the legend is in the same order and orientation as the stacks in each bar. Also notice that this is stated under the chart title.

Remember that for the legend to be useful, users will still need to be able to see where one stack ends and another begins. Making sure adjacent colours meet the contrast requirements will help with this.

Patterned bars

Sometimes patterned bars are suggested as a way to help users match labels to data using a legend. If different colours are used alongside patterns this is OK from a digital accessibility point of view as neither shape nor colour are being used on their own.

But, we do not recommend it as it is not best practice. Patterned bars can make charts very cluttered and hard to understand. They may also suggest provisional or incomplete data.

See the module on formatting rules (link opens in a new tab) for more information.

Back to top of page

Quiz

Try these questions to test your knowledge from this module

 

Download a plain text version of module 7 quiz (ODT, 9KB)

End of module 7

Next, module 8: Line charts

Back to landing page.

Back to top of page
  • If you would like us to get in touch with you then please leave your contact details or email Analysis.Function@ons.gov.uk directly.
  • This field is for validation purposes and should be left unchanged.