In my second week at the Data School, I learnt how to produce a diverging bar chart in Tableau without having to use negative values for one of the axes, and with consistent scaling for both sets of bars.
Diverging bar charts can be useful to compare the distributions of two similar measures - for example, with the Superstore data, we may want to visualize both 2020 and 2021 sales by category. First, we create two sets of bar charts for each year:
Next we edit the first graph’s axis so it is reversed, with the bars starting from the right side.
Adding mark labels results in the chart above. However, the 2020 and 2021 sales are on different scales, with the 2020 axis going up to 90k, and the 2021 axis going up to 120k. This makes visual comparisons between the bars less meaningful. To fix this, you could simply edit the 2020 axis to have the same start and end values as the 2021 axis. However, if the data is still being updated, you would have to do this manually every time new data is added.
Instead, we can add invisible reference lines on both sides to ensure both charts are always on the same scales.
To do this, we add the measure for 2021 sales to the Detail card in the 2020 Marks card, and vice versa.
We add a reference line by dragging it from the Analytics pane to where Table and 2020 Sales cross, then setting it to the maximum of 2021 sales. Set all the formatting to “None” to make the line invisible, then repeat the steps for 2021 sales using the maximum value of 2020 sales.
Adding colour and unchecking the axis headers will result in the final chart: