Polygon Map with Tableau Public

In the previous chapter, we looked at using Tableau Public to build scatterplots and filtered line charts. Tableau can also be used to create point and polygon maps.

In this tutorial, we will create a choropleth map of military spending per country as percentage of gross dometic product as shown in Figure 6.27. Remember that choropleth maps work best when they show relative, not absolute numbers. Displaying total spending per country is a bad idea, as bigger countries tend to have larger populations and as a result larger values for a lot of measures, including military spending.

Figure 6.27: This choropleth map is made in Tableau Public

To create maps in Tableau, you do not always need geospatial files. Tableau can recognize of a lot of locations, including boundaries for countries and territories, counties within countries, states, US zip codes, airport codes, city locations, and some others. A simple spreadsheet that references these locations can suffice. In this tutorial, we will rely on Tableau to automatically recognize country names. If you require custom boundaries or points (such as town names in your local language), take a look at Create Tableau Maps from Spatial Files article from the official Tableau documentation.

Before we begin, download the 2018 data that we obtained from the World Bank.

Create a Choropleth Map in Tableau

Launch Tableau. In Connect section on start up, choose Text file, and select military-spending-2018.csv. From Data Source tab, inspect the dataset contents. It contains four columns: Country Name, which includes countries and territories defined by the World Bank, the three-digit Country Code, Indicator Name (same for all rows), and percent value, as shown in Figure 6.28. Notice that some values are set to null (not available).

When finished inspecting the connected file, go to Sheet 1.

Figure 6.28: When finished inspecting the connected file, go to Sheet 1.

In the variables list on the left, notice how Tableau generated Latitude and Longitude fields based on country names and country codes (by the way, you only need one or the other, not both).

Drag and drop Longitude to Columns, and Latitude to Rows, as shown in Figure 6.29. You should see that the chart area shows an empty map of the world (if not, double-check that Latitude is indeed in Rows, not Columns). In Marks box, change Automatic to Map, and drag Country Name variable to the Size box of the Marks card. You will see that country outlines turned blue.

Drag and drop variables to the right places.

Figure 6.29: Drag and drop variables to the right places.

We want colors to represent military spending values, so drag Value variable to the Color box of the Marks card. You should now see a proper choropleth map.

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 6.30).

Filter values to remove countries with no data from display.

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

You can change the color scheme by clicking the Color box of the Marks card, and then Edit colors. Change the palette to Reds, and make it stepped rather than continuous, as shown in Figure 6.31.

Change the color scheme to Reds with 5 steps.

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

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 6.32. Make sure not to change values between < and >, as these are references to variables.

Change tooltip text to make it more user-friendly.

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

And finally, let’s 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 (2018).

Publish Your Tableau Map

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.

Summary

In this chapter, we looked at free mapping platforms to create simple point and polygon maps. Google My Maps is a good choice for point maps that can be created in collaboration with others. If the data you are interested in lives on Socrata platform, you might be able to create a point map within the platform itself, and embed it as an iframe in your own website. Tableau is another very powerful tool to build and share polygon and point maps.

In reviewing all these tools, we only scratched the surface and showed simple examples to get you started quickly. All platforms allow layering data to create powerful exploration mapping visualizations.

None of the platforms required special geospatial data, as all were smart enough to perform geocoding and know the boundaries and coordinates of objects given to them. In Chapter 11, we will talk more about geospatial data, how it can be obtained, stored, modified, and shared.