How To Create a Bar Chart on a Map in Tableau

One of my students asked how to create a bar chart on a map in Tableau. There is a built-in option in Tableau for symbols on maps and pie charts on maps, but there is no option of a standard bar chart on a map. However, it is possible to create a bar chart on a map. Here's an example.

So how is this done? Have you heard of the "Cotgreavean Toolips"? If you are new to Tableau then you might not remember this very famous blog post by Andy Cotgreave. Two days ago marked the 6th year anniversary of this post, a milestone I know he tracks. In his post he showed the world how to create bar charts in tooltips. I will use this same method to create bars, but with a twist, I will put them on a map as a bar chart.

For this demo I will use the Superstore data in Tableau.

Step 1 - Create Calculated Fields for the Bars

This is identical to the original post about bar charts in tooltips, we need to create fields for each bar.

Calculated field name: Calculation Furniture
Formula: IF [Category]="Furniture" THEN [Sales] END

Calculated field name: Calculation Office Supplies
Formula: IF [Category]="Office Supplies" THEN [Sales] END

Calculated field name: Calculation Technology
Formula: IF [Category]="Technology" THEN [Sales] END

Calculated field name: % Furniture Bars
Formula: LEFT ("██████████", ROUND(SUM([Calculation Furniture])/SUM([Sales])*10,0))

Calculated field name: % Office Supplies Bars
Formula: LEFT ("██████████", ROUND(SUM([Calculation Office Supplies])/SUM([Sales])*10,0))

Calculated field name: % Technology Bars
Formula: LEFT ("██████████", ROUND(SUM([Calculation Technology])/SUM([Sales])*10,0))

Note: this is rounded to the nearest 10 instead of 100 to make it space-friendly for the map.

Step 2 - Build the Map

Double click State. This will put Longitude on Columns and Latitude on Rows.
Change the Marks dropdown box to Text.
Drag your new Bars fields to Text; % Furniture Bars, % Office Supplies Bars,% Technology Bars.
Click Size and make the size as small as possible.

You now have 3 bars on your map representing the % of each in the category for the state.

Step 3 - Format the Text for the Bars

Horizontal bar chart on a map:

Click on Text and select the alignment dropdown.
Set Horizontal Alignment to Left.
Click on the three dots ... to edit the text box.
Select all of the text and set the font to size 8. Highlight each row in the text box and change the color to the color you want the bars to be in the bar chart.

Here is an example of how I formatted them.

Vertical bar chart on a map:

For vertical bars we simply adjust the text alignment.
Click on Text and select the alignment dropdown.
Set Text Alignment to Up.
Set Vertical Alignment to Bottom.

Stacked bar chart on a map:

For stacked bars, simply put all of the labels on the same line and adjust the text to normal or up for either horizontal or vertical stacked bars.

These formatting options will allow for bar charts or stacked bars in both vertical or horizontal orientation. Here is a link to an example workbook to download.

Additional Commentary:

Showing a part-two-whole relationship on a map is a difficult problem. Pie charts are not considered data visualization best practice, but because there is no easy way to show this it is generally accepted that pie charts on a map are an acceptable use. Bar charts would be one alternative, but there isn't a common baseline between states, only within a single state. So it's pretty easy to make a single comparison in a state, but hard to compare state to state. In addition, there is the issue of overlapping marks, so be careful of the size. Stephen Few proposed bricks on a map as a way to show data on a map in his article Building Insight with Bricks. Steve also discusses some of the issues with his approach in a follow up post What Can't be Built with Bricks? based on further discussion with Joe Mako about this approach, specifically overlapping marks. Be mindful of these issues when you are plotting bars or stacked bars on a map.

I hope you find this information helpful. If you have any questions feel free to email me at Jeff@DataPlusScience.com

Jeffrey A. Shaffer
Follow on Twitter @HighVizAbility