Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Tableau Playbook - Diverging Bar Chart Part 2

Jul 15, 2019 • 11 Minute Read

Introduction

This is the second part of a three-part series on Tableau Playbook - Diverging Bar Chart. In the first part, we delved into basic concepts and the butterfly chart. Check it out in case you missed it.

In this guide (Part 2), we will focus on another diverging bar chart: the Standalone Diverging Bar Chart. We will learn it in the following steps:

  1. We will start with an example chart, then introduce the concept and characteristics of it.

  2. By analyzing a real-life dataset: birth rate of the United States, we will learn how to build this diverging bar chart step by step. Meanwhile, we will draw some conclusions from our Tableau visualization:

    1. Build the chart based on the basic process.
    2. Optimize and polish the chart with advanced features.

Standalone Diverging Bar Chart

Example

Here are two examples using standalone diverging bar charts from the New York Times and JoeyCloud.

The left chart shows positive and negative factors that affect lifespan. The right diverging histogram shows the frequency of piano keys.

A standalone diverging bar chart contains one dimension and one measure, or only one measure in a diverging histogram. It highlights the double-edge of a dimension, such as the positive and negative factors in the left example.

Basic Process

For the U.S. Birth Rates dataset, we will display the time trends of the birth rates from a specific age group. In order to highlight the difference between growth and reduction, we use the average birth rate as the baseline.

Let's draw a basic standalone diverging bar chart step by step:

  1. Create bins to decrease the "Year" dimension: right-click "Year" dimension -> choose Create - Bins... -> edit Size of bins to 2 in the pop-up dialog -> drag it into Column Shelf.

    standalone diverging basic process 1

  2. Create a Calculated Field "Birth Rate Diff" which calculates the difference from average value: right-click in the blank of Data Pane -> choose Create Calculated Field... -> input the formula [Birth Rate] - {FIXED [Age Start] : AVG([Birth Rate])} -> drag it into *Rows Shelf.

  3. Create a filter for age group:

    1. Drag "Age Start" dimension into Filters.
    2. The "Filter [Age Start]" dialog will pop up automatically. Only check "30” in the value list.
    3. Right-click "Age Start 30" in Filters and choose Show Filter.

    standalone diverging basic process 2

  4. Right-click "SUM(Birth Rate Diff)" on Rows Shelf and choose Measure -> Average.

  5. Hold down the Control key (Command key in mac) and drag "AVG(Birth Rate Diff)" into Marks - Color.

  6. In the last step, let's polish this chart:

    1. Right-click "Age Start" and edit Aliases... Then edit in Value (Alias) column.
    2. Bind title with parameter: click Insert and choose "Age Start" to bind, like "Birth Rate Time Trends of Age Group".
    3. Edit colors in Legend: click the inverted triangle in Legend and choose Edit Colors...
      1. Choose Red-Green Diverging in Palette to make color self-explanatory.
      2. Expand Advanced option, then set Start as -35 and End as 35.
    4. Rename Legends as "Age Group of Mother" and "Birth Rate Difference".
    5. Hide the vertical and horizontal axes.

    standalone diverging basic process 3

A standard standalone diverging bar chart is completed.

Here is a defect in the basic version. In order to make bars divided by zero-axis, we used a calculated field to compute the difference from the average, but axis values become relative. We will solve this problem in the next section.

Advanced Features

Non-zero Axis as the Baseline

To optimize the above chart, we will keep the absolute values and use a non-zero axis as the baseline, with the help of Gantt Bar.

  1. Create a Calculated Field "Birth Rate Diff 2" for Gantt Bar: right-click in the blank of Data Pane -> choose Create Calculated Field... -> input the formula ([Birth Rate]-{FIXED [Age Start] : AVG([Birth Rate])})*-1

    non-zero axis 1

  2. Replace "AVG(Birth Rate Diff)" to "AVG(Birth Rate)":

    1. Drag "Birth Rate" into Rows Shelf.
    2. Right-click "SUM(Birth Rate)" on Rows Shelf and choose Measure -> Average.
    3. Remove "AVG(Birth Rate Diff)".
  3. Change Marks type from Automatic to Gantt Bar.

  4. Set the Size of Gantt Bar:

    1. Drag "Birth Rate Diff 2" into Marks - Size.
    2. Right-click it and choose Measure -> Average.

    non-zero axis 2

  5. Add colors to Gantt bars:

    1. Hold down the Control key (Command key in mac) and drag "AVG(Birth Rate)" into Marks - Color.
    2. Click Color in Marks and click Edit Colors...
    3. Choose Red-Green Diverging in Palette.
  6. Change the Legend type to Single Value (list). Thus, we can switch the age group in the Legend to explore more information.

    non-zero axis 3

From the above final chart, we can see this diverging bar chart is divided by a non-zero axis and displays the absolute values.

Clean Labels

To make the chart more readable, we can clean both dimension and measure labels and make them closer to the bar. This section is inspired by TableauTimothy. Let's Duplicate the basic chart and reform on it:

  1. Click Swap Rows and Columns to make the chart look clearer.

  2. Drag the "PlaceHolder" into Columns Shelf.

    clean labels 1

  3. Create two Calculated Fields:

    "Positive Year Label": IF [Birth Rate Diff] > 0 THEN [Year] END

    "Negative Year Label": IF [Birth Rate Diff] < 0 THEN [Year] END

  4. Drag "Positive Year Label" into the first Marks - Label, and drag "Negative Year Label" into the second Marks - Label. Then right-click and choose Measure (Minimum) to show the start year.

  5. Here, we use the dual axis technique to display dimension labels on both sides:

    1. Right-click "SUM(PlaceHolder)" and check Dual Axis.
    2. Then right-click the axis and check Synchronize Axis.
    3. Next, hide the vertical and horizontal axes.

    clean labels 2

  6. Configure in Marks - "AVG(Birth Rate Diff)":

    1. Change the type from Automatic to Gantt Bar.
    2. Format Text: set Alignment to Left, set Color to green and Bold.
    3. Hold down the Control key (Command key in mac) and drag "AVG(Birth Rate Diff)" into Marks - Size.
    4. Double click the Size pill and edit (add - in the head): -AVG([Birth Rate Diff])
  7. Configure in Marks - "SUM(PlaceHolder)":

    1. Change the mark type from Automatic to Bar.
    2. Format Text: set Color to red and Bold.
  8. Dimension labels have been placed on both sides successfully. Now, we will work on the measure labels because a mark can only support one alignment. So, we need Reference Lines to display measure labels on the opposite side:

    clean labels 3

    1. Create two Calculated Fields: "Positive Birth Rate Label": IF AVG([Birth Rate Diff]) > 0 THEN AVG([Birth Rate Diff]) END "Negative Birth Rate Label": IF AVG([Birth Rate Diff]) < 0 THEN AVG([Birth Rate Diff]) END
    2. Drag "Positive Birth Rate Label" into the first Marks - Detail, and drag "Negative Birth Rate Label" into the second Marks - Detail.
    3. Switch to Analytics tab and drag Reference Line into Cell "AVG(Birth Rate Diff)".
    4. An edit dialog pops up automatically:
      1. Choose "AGG(Positive Birth Rate Label)" in Line - Value.
      2. Choose Value in Line - Label.
      3. Choose None in Formatting - Line.
    5. Right-click any reference line and click Format...
      1. Format the Font: set Color to red and Bold.
      2. Format the Alignment: make it left-aligned horizontally and center-aligned vertically.
    6. Repeat similar steps for the second field.

    clean labels 4

With the help of dual axis and reference line, we customize both dimension and measure labels on a diverging bar chart and make it cleaner.

Analysis

With the help of a standalone diverging bar chart, we can see the time trends more intuitively.

For the age group of 30-34, there are two positive regions (green bars). One is from 1942-1964, the other is from 2000-2013. Let's infer the possible reasons. The first mountain is caused by World War II. The United States advocated more births for recovery and development. The reason for the second mountain is that modern people tend to postpone their marriage and childbirth.

Side Effect

When you use a standalone diverging bar chart and make a relative comparison, be careful with the meaning of the two sides because the misuse of a diverging bar may cause misleading statistics. For more information you can refer to Mona Lebied's blog.

Conclusion

In this part, we have learned a standalone diverging bar chart. First, we learned the standard process to create a standalone diverging bar chart, and then we dug into the situation which needs a non-zero axis as the baseline.

In the third part of this series, we will focus on Diverging Stacked Bar Chart and compare with other bar charts.

You can download this example workbook Bar Chart and Variations from Tableau Public.

In conclusion, I have drawn a mind map to help you organize and review the knowledge in this guide.

I hope you have enjoyed it. If you have any questions, you’re welcome to contact me recnac@foxmail.com.