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 6. 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. We’re showing you how to create the same type of map with both tools, in order to show you the difference. On one hand, Datawrapper gives you more control over interpolating data and shaping the appearance of color intervals in your choropleth map. On the other hand, some people prefer Tableau Public because they’re already familiar with its interface.

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 2. 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 healthcare spending per country as a percentage of their gross domestic product (GDP), as shown in Figure 7.52. Remember that choropleth maps work best when we normalize the data to show relative, rather than absolute, numbers. Creating a map of total health 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 healthcare.

Before we start, you should obtain and install the free Tableau Public desktop application if you don’t have it yet. It is available for Mac or Windows. You will need to enter an email address to download the application.

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

Let’s look at the steps involved to create a choropleth from Figure 7.52 in detail.

  1. Open the Healthcare 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 4. 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. In the Google Sheet, go to File > Download and select Comma-Separated Values (CSV) format to save the data to your local computer.

  2. Launch Tableau Public. When you first open it, you will see the Connect menu on the left-hand side that displays file formats you can upload. Choose the Text file format and upload the healthcare spending CSV data file you’ve just downloaded in the previous step.

Note: Tableau lets you access data directly from Google Sheets that live in your Drive using Connect > To a Server option. So instead of downloading a CSV file in step 2, you could have made a copy of the sheet, and connected to it directly.

  1. In the Data Source screen, inspect the dataset, which contains three columns: Country Name, Country Code, and Health Spending As % of GDP. Notice that a small globe appears at the top of the Country Name and Country Code columns, which shows that Tableau Public successfully recognized these as geographic data, rather than string or text data. Sometimes Tableau does not recognize location data automatically, so you need to manually change the data type. To do so, click the data type icon (e.g. globe or a green # for numeric values), and then choose Geographic Role > Country/Region as shown in Figure 7.53.
Make sure Tableau Public knows that the Country Name column contains geographic data.

Figure 7.53: Make sure Tableau Public knows that the Country Name column contains geographic data.

  1. In the bottom-left corner, click the orange Sheet 1 button to create a worksheet with your first visualization, as shown in Figure 7.54.
Click the orange button to go sheet 1 where you can create your map.

Figure 7.54: Click the orange button to go sheet 1 where you can create your map.

  1. In Sheet 1, create your choropleth map using a two-step process, as shown in Figure 7.55. First, drag-and-drop the Country Name field into the middle of the worksheet (alternatively to the Detail box of the Marks card) to create the map. The default view is the symbol map, which we need to replace with a polygon map. To add colored polygons, drag-and-drop the Health Spending As % of GDP field into the Color box of the Marks card to transform it into a choropleth map.
Drag and drop Country Name to the center of the sheet, then Health Spending As % of GDP to the Color box in the Marks card.

Figure 7.55: Drag and drop Country Name to the center of the sheet, then Health Spending As % of GDP to the Color box in the Marks card.

  1. Tableau Public may hide the map legend behind the Show Me menu in the upper-right corner, 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 Green, and change it from continuous to steps, as shown in Figure 7.56.

Change the color scheme to Green with 5 steps.

Figure 7.56: Change the color scheme to Green with 5 steps.

  1. When you hover over countries, you will notice a tooltip that tells you the name of the country and gives you the percent value. It is generally well-formatted as our initial data table had proper column headers. But we can make the toolitp even better. Click the Tooltip box of the Marks card, change the first instance of Country Name to just Country (do not change the grayed-out text inside < and > as these are variable names), and add a % sign at the end of the second row, as shown in Figure 7.57.
Change tooltip text to make it more user-friendly.

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

  1. Let’s make our map title more meaningful. Double-click the default Sheet 1 name just above the map to bring up the Edit Title window, and change the name of your chart to 2017 Healthcare Spending by Country as % of GDP.

  2. At this point the data is loaded and should be displayed correctly, so we are going to create the final layout that include map’s title and credits, the legend, and is appropriate for sharing. At the bottom-left of the program, create a New Dashboard, as shown in Figure 7.58. Dashboards in Tableau are layouts that can contain visualizations from multiple sheets, as well as text boxes, images, and other elements, creating rich exploratory interfaces. In this tutorial, we will stick to just a single sheet that contains our choropleth map.

Before you publish the map, create a new dashboard to finalize your layout.

Figure 7.58: Before you publish the map, create a new dashboard to finalize your layout.

  1. In your Dashboard 1 tab, change the size of the dashboard to Automatic so that the map is responsive and occupies 100% of the width on all devices. Drag and drop Sheet 1 to the Drop sheets here area, as shown in Figure 7.59. This will copy the map, the title, and the legend from Sheet 1.
To create a responsive dashboard, change the Size to Automatic.

Figure 7.59: To create a responsive dashboard, change the Size to Automatic.

  1. Right-click the upper part of the map legend, and select Floating, as shown in Figure 7.60. Now you are able to place your legend directly on top of the map to save space. Drag and drop it to one of the map’s corners.
To place the legend on top of the map, make sure it is floating.

Figure 7.60: To place the legend on top of the map, make sure it is floating.

  1. Finally, let’s add a text block with data source underneath the map. From the Objects menu in the left-hand side, drag and drop Text to the lower half of the map. In the Edit Text window that appears, type Data by the World Bank, 2017, and click OK. Initially the text area will occupy half the height of the screen, so resize it like you would resize any window on your computer.

And we’re done! Make sure you position your map’s center and zoom level as you want it to be visible by others. In this case, the best would be to have a world view as we are showing data for most countries, although you may want to zoom in to a specific continent. 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 Healthcare Spending, and click Save. See how to embed the map as an iframe in Chapter 9.

Warning: Tableau may not be the best tool to create choropleth maps where you want to have full control of color breaks. By default, Tableau uses a linear color scheme that, as we’ve learned earlier in the chapter, is prone to highlighting outliers, and there is no straightforward way to change the intervals to non-linear methods such as quantiles. If you are not happy with the way the linear scale represents your data, you can filter your data to remove outliers from the map, or see Andy Kriebel’s VizWiz tutorial to use table calculations to group items into quantiles, or create your choropleth map in Datawrapper, which gives you more control over color intervals and interpolation.

In all of the prior tutorials, you created interactive maps using static data, meaning it came from a spreadsheet. In the next tutorial, you’ll learn how to build a map using continuously-updated data from a Socrata open data repository, which will always display the most current information.