1. When to use bars
Now that we're experts in visualizing proportions of a single population, we may start to ask ourselves, 'what if I want to compare multiple wholes to each other'?
2. Why not use faceting?
As someone who has completed the DataCamp series on ggplot you may think to yourself, 'why not use faceting?' This good intuition but unfortunately, it's not ideal for when you are plotting with pie or waffle charts.
This is because when you place a bunch of pie or waffle charts next to each other there is no easy anchoring point for you to make out-of-group comparisons amongst the different populations.
Here, we are looking at the proportion of cases for different diseases across the countries in the south east Asia region. It's almost impossible to make meaningful comparisons across the countries. Luckily, there is a better way.
3. The stacked bar chart
We can make a stacked bar chart by un-rolling our pies into bars and putting them on the x-axis according to their group. Now to compare diseases across countries we simply need to scan across the x-axis. Compared to the previous faceted pies, we have a much more precise and information dense chart.
Note the use of the position = fill argument in geom_col. This causes the bars to stretch all the way to the top of the y-axis, making them proportion charts. If we left this argument out the bars would all be different heights due to different total numbers of classes. In this scenario, this would just obscure the point of the chart, but it can be useful in other scenarios!
4. Caveats
Unfortunately, stacked bars suffer from some caveats that prevent them from always being the correct visualization for a problem.
First, like a pie chart, there is a lack of anchoring for in-group comparisons for anything other than the first and last classes.
Additionally, the stretched vertical shape in comparison to the nice compact circle or square of pie and waffle charts leads to increased effort in jumping between classes.
These caveats result in two best-practices. First, don't make a stacked bar in isolation. Studies have shown that isolated stacked bar charts are less precise than even a pie chart and much worse than a waffle chart. Second, keep the number of classes small just as you do with a pie chart.
If however, your goal is to compare lots of populations makeups to each other, stacked bars are a fantastic chart type to use.
5. Chapter recap
To recap what we've discussed in this first chapter:
The type of data we discussed in this chapter are proportions or data that sums to some meaningful whole, like how water and land area sum to the entire surface of the earth.
The first visualization we dug into was pie charts: These are great for quick visualizations of proportion data for a single group. They suffer from accuracy problems due to encoding data in angles but are intuitive and compact.
If you need more precision in your representations than a pie chart can offer, want to compare more classes than three, or simply have the space. Waffle Charts are a fantastic drop-in replacement to pie charts.
If you want to compare different wholes to each other you should use a stacked bar chart, as they allow the viewer to easily compare across groups due to all proportions sharing the same y-axis.
6. Let's practice!
Enough talking about boring best-practices, though, let's actually make some stacked-bar charts with our WHO data!