Choropleth Map with Tableau Public

We first introduced you to the free Tableau Public desktop application (for Mac or Windows) when building scattercharts and filtered line charts in Chapter 7. Now let’s use the same tool to create an interactive choropleth map, and compare the process with the Datawrapper tool we learned in the prior section. Tableau Public can create many different types of map for geographical place names or ISO codes it already recognizes, such as nations, states, counties, and airports. But Tableau Public cannot geocode street addresses by itself, so you’ll need to obtain their latitude and longitude with another tool, such as those described in the geocode section of Chapter 3. Furthermore, if you want to upload customized map boundaries, learn how to Create Tableau Maps from Spatial Files on the support page.

In this section, we will create a choropleth map of military spending per country as a percentage of their gross domestic product (GDP), as shown in Figure 8.40. Remember that choropleth maps work best when we normalize the data to show relative, rather than absolute, numbers. Creating a map of total military spending per country would not be very meaningful, as larger nations tend to have larger economies, so we’ll base our map on the percentage of their economy that is spent on the military.

Figure 8.40: Choropleth map of military spending with Tableau Public. Explore the interactive version. Data from the World Bank.

TODO above: update the demo map to match our current data and instructions (without filters?), after we make decisions about how to address interpolation in the note at the bottom of this section.

To create your own choropleth map with Tableau Public, follow this tutorial.

  1. Open the Military Spending by Nation as Percent of GDP data in Google Sheets, which we downloaded from the World Bank. Examine the data and the notes.

Good maps often require cleaning up messy data as described in Chapter 5. In our spreadsheet we removed rows for nations that did not report any data. Tableau Public recognizes many different types of geographic names (such as cities and nations), so we will rely on the tool to deal with any spelling issues and properly place all of them on the map.

  1. Go to File > Download in CSV format (comma-separated values) to save the data to your local computer.

  2. Download, install, and launch the free Tableau Public desktop application, available for Mac or Windows. It will require you to enter an email address.

  3. In the Connect screen, select Text file, and upload the military spending CSV data file you downloaded above.

  4. In the Data Source screen, inspect the dataset, which contains three columns: Country, Most Year Year of the data, and Military Spending as Percent of GDP. Notice that a small globe appears at the top of the Country column, which shows that Tableau Public successfully recognized it as geographic data, rather than string or text data. If that globe was not there, you can select its menus to set its proper geographic role, as shown in Figure 8.41.

Confirm that Tableau Public recognizes your geographic place names.

Figure 8.41: Confirm that Tableau Public recognizes your geographic place names.

  1. In the bottom-left corner, click the orange Sheet 1 button to go to the Worksheet to create your map, as shown in Figure 8.42.
Click the orange button to go to the worksheet to create your map.

Figure 8.42: Click the orange button to go to the worksheet to create your map.

  1. In the Worksheet, create your choropleth map using a two-step process, as shown in Figure 8.43. First, drag-and-drop the Country geographic data into the middle of the worksheet to create the map, which will temporarily appear as a point symbol map. Second, drag-and-drop the Military Pct GDP data values into the Color box of the Marks area to transform it into a choropleth map.
Drag and drop Country to the center of the sheet, then Military Pct GDP to the Color box in the Marks area.

Figure 8.43: Drag and drop Country to the center of the sheet, then Military Pct GDP to the Color box in the Marks area.

  1. Tableau Public hides your map legend menu behind the Show Me menu, so click the menu to shrink it and display your legend.

  2. You can change the color palette by clicking the Color box of the Marks card, and then Edit colors. Change the palette to Reds, and change it from continuous to steps, as shown in Figure 8.44.

Change the color scheme to Reds with 5 steps.

Figure 8.44: Change the color scheme to Reds with 5 steps.

  1. You may notice the tooltip calls values Value when hovering over countries. Click the Tooltip box of the Marks card to change text to Military spending, and add a percentage sign after the value itself, as shown in Figure 8.45. Make sure not to change values between < and >, as these are references to variables.
Change tooltip text to make it more user-friendly.

Figure 8.45: Change tooltip text to make it more user-friendly.

  1. Add a proper title to the map. Double-click the default Sheet 1 name to bring up the Edit Title window, and change the name of your chart to a more meaningful Military Spending as % of GDP (most recent year).

  2. TODO: Improve these instructions…. Create Dashboard and Publish Your Map… change color range menu to floating, place on top of map, add title and sources…

  3. Once you are ready to publish and share the map, go to File > Save to Tableau Public. In the pop-up window, log in to your account if requested. Give it a title, such as Military Spending, and click Save.

Now that you understand how to create maps using static data from a spreadsheet, let’s explore how to create a map using the most current data available from an open-data repository.

TODO above to DISCUSS: We might have a mismatch between the data and the tool here. If you do a quick histogram of the military data, most values are clustered around the median, but there’s a few really high-spending outliers. This makes it difficult for novices to map in Tableau Public, because the default interpolation is linear, and the outliers dominate the appearance of the map. It’s not clear to me how to change this to quartiles or natural breaks, as we do in Datawrapper. Perhaps there are some ideas here: OR one of these Tableau books by Ryan Sleeper (but I don’t see anything right away that’s relevant) OR another idea is to reconsider the filter instructions below, which I removed because our sample dataset no longer has null values.

Places like Greenland and Libya do not have available values, but they are still painted with the lightest color, which is misleading. To remove countries with null values from the map, drag Values to the Filters card. A popup window will ask you how you want to filter, just leave everything unchanged. This will leave the whole range of values, and exclude null values (see the checkbox in the lower-right corner of the Filter window in Figure 8.46).

Filter values to remove countries with no data from display.

Figure 8.46: Filter values to remove countries with no data from display.