Chart Talk! Bar Charts
The use of bars to visualize a measure for a set of discrete elements was groundbreaking, and paved the way for further advancements in statistical graphics. Looking at the chart above, it is instantly clear which countries imported and exported the most goods with Scotland in 1781.
So, how do I build one?
Constructing a simple bar chart in Tableau is made extremely simple through Tableau’s user-friendly interface. You will need to ensure that your data is shaped correctly to avoid common mistakes such as incorrectly aggregating data. All examples below will use Tableau’s well-known Superstore data set.
1 - Basic Bar Chart
A basic bar chart consists of a single discrete dimension – category, name, year, etc. – and a single quantity to measure – sum of sales, count of distinct customer names, average discount.
For our first example, drag the Discount measure onto the rows shelf. Tableau will automatically build a bar, in this case showing the average discount across all values in the data set. Changing the number format to show one decimal point tells us that the average discount is 15.6% across all records.
You now want to look at how the average discount differs across each customer segment. Drag Segment onto the columns shelf and one bar becomes three – one for each value of segment. From this view we can easily see that the home office segment has, on average, the lowest average discount. The average discount for consumer and corporate segment customers is nearly identical.
Two click-and-drag actions and we have built our first simple bar chart. Formatting the chart by removing unnecessary labels, adding relevant information to the tooltip, or coloring to match your company’s logo can all add flavor to the chart. In a few seconds we have told a story with our data. Now be prepared to dig further; why are home office discounts lower?
Let’s now move on to creating a slightly more complex graphic – the clustered bar chart.
2 - Clustered Bar Chart
In many cases a simple bar chart is sufficient to answer the question at hand. Consider, however, that you now want to see how the average discount varies between product categories within each segment. Using the example from above, drag Category onto the columns shelf and drop it to the right of Segment. The order in which dimensions are placed is important in Tableau. The left-most dimension will be the “parent,” while each dimension to the right will be a “child” element, nested inside of all parent dimensions. In the image below you can see each segment listed above the bar chart, and underneath each segment pane we see repeated labels for each category.
Swap the dimensions; what do you see now? Does it make more sense to configure it one way versus another?
With one more drag-and-drop action we have turned the basic bar chart into a clustered bar chart based on two dimensions. As the chart becomes more complex, consider adding formatting elements that will help distinguish groups in the data. Try adding column banding or coloring the bars by segments.
3 - Stacked Bar Chart
- It can be very difficult to compare the relative sizes of the segments in the same bar and across different bars. If you have to use a stacked bar chart, try to keep the number of segments to a minimum. The only segments that can be reliably compared across bars are those that begin on the axis.
- With Tableau’s “stack marks” option turned on, the quantitative axis of your stacked bar chart may be nonsensical. This is where understanding your data and the information you’re trying to convey is critical for a successful visualization.
Building a stacked bar chart
For this section will we go back to the first example where we placed Segment on the columns and average Discount on the rows shelves. Let’s build a stacked bar chart and address point 2 from above.
Take Category and drag it onto the colors mark. This will create a stacked bar chart where each column represents a segment, each color within a bar is a category, and the height of each colored section within a bar (and, subsequently, the bar as a whole) is the average discount for that segment/category combination.
This might seem okay at first glance, but now look at the scale of the quantitative axis. It goes up past 45% – this is far higher than any segment/category average discount. What went wrong?
To stack or not to stack
Tableau’s default behavior is to stack marks on top of one another. Thus, if the bottom segment is 12%, the middle segment is 15%, and the top segment is 18%, the total height of the bar will be 45%. In some cases this is desirable, but in this example it makes more sense to unstack the marks.
To unstack marks in Tableau, hover over the Analysis tab at the top of the window, then hover over Stack Marks. With that menu open, select the Off option. Your chart should now look like the example above on the right.
Note that you will likely need to sort the chart by the dimension over which you are coloring the bars by. By default, Tableau will sort string dimensions alphabetically. Because of this, the tallest bar may placed in front of all other bars, causing it to be the only partition visible. You will likely want to sort the coloring of the bars by the aggregated measure in your chart – average discount in our case. To do this, right-click on the Category dimension on the color mark and select Sort to open the sort dialog. Set the sort order to Ascending, sort by the discount field with an average aggregation.
Finally, be aware that the sorting that we applied above will be applied to ALL bars in the chart. There is a possibility that no matter how you sort your color dimension that some partitions will be obscured. We recommend trying a different chart type if this is the case.
100% stacked bar chart
Finally, we will look at how to make the bars total to 100%.
Showing the percentage of total for each bar, with all partitions adding up to 100% is a common strategy to show the distribution of data.
Drag Segment onto the columns shelf, and this time drag Sales onto the rows shelf. Drag Category onto the color mark. It is instantly clear which segment has the highest sales; what we now want to do is perform a table calculation that will show us what percentage of sales each category makes up for each segment.
Use of Color
The use of color in visual storytelling is often crucial to the end user’s experience. Color can be used to distinguish one dimension from another, to show the gradient between the minimum and maximum values in a series, to highlight a specific mark, or simply to keep the theme consistent with a company’s brand.
To that point, there is a large body of research into color perception. It is typically advisable to limit color legends to no more than 5 to 7 distinct colors. If you cannot reduce the number of colors in your legend, consider using other means of differentiating your data – sparklines and small multiples are worth mastering.
Also, your color palettes should be color blind-friendly. According to the National Institutes of Health, upwards of 8% of men and 0.5% of women experience some form of color blindness, with the most common type being red-green color blindness.
Tableau comes packaged with a color blind-friendly palette. If you must use company colors, use one of the many free online tools to ensure that your color choices can be appreciated by as large an audience as possible.
Common Pitfalls to Avoid
Even a simple bar chart can be extremely misleading if you’re not careful. As an analyst or developer, accuracy and representing data honestly is the most important element of sound analysis.
When speaking professionally, I try to avoid definite statements (always, never, certainly), but bar charts should never begin anywhere other than 0 on the quantitative axis. Bar charts are effective because humans are fairly good at comparing differences in one dimension, such as height or length. By setting the baseline of a bar chart to any value other than 0, you are excluding some portion of the bars, which causes the apparent differences in bars to become magnified.
In the three sets of examples above, we have created bar charts in Tableau based on the same data as the original charts. The charts to the left all have their baseline at some value other than 0, while the Tableau charts to the right all begin at 0.
What should be instantly obvious is the distortion caused by truncating the quantitative axis. In the last example, the bars to the right look almost flat, while those to the left appear to have more than doubled in height.
Wrapping it all Up
After reading through this edition of Chart Talk, we hope that you feel comfortable building effective bar charts in Tableau. As we’ve shown, building a bar chart is very easy to do, and they can be a fantastic way of communicating data. A great benefit of bar charts is their ease of understanding. One doesn’t need a PhD in Chart Reading to understand a bar chart.
When publishing visualizations of your own, remember principles of sound design, such as keeping your color palette color-blind friendly, not using too many colors, and using extra formatting elements only when it enhances the visual.
Finally, don’t allow your chart to be misleading. Title and label your chart correctly so your audience knows what they are looking at. Make sure your bars start at 0. Remember that some members of your audience may not be data savvy, and can easily be mislead.