Being able to compare data across geographies is critical for any business. Imagine if an organization is doing business in multiple locations; the analysis of interest would be to find out which region is giving high sales, which region is profitable, which region has the maximum customer base, and so on.
Our data may consist of geographic fields such as countries, states, cities, and so on, and when we are analyzing these fields, it makes sense to plot them on a map, primarily because it is easier to compare information across regions to find various geographic trends.
Tableau has many data-map providers and it comes with a set of Online and Offline maps that one can access to create the maps views. Further more, Tableau understands various geographic roles as well, and once it does that, it will create a small globe icon as a prefix for that field. Refer to the following image:
Tableau will also auto generate two measures: Latitude (generated) and Longitude (generated). We will use these fields to plot the geographical data on the map in Tableau. In the following recipe, we will learn the steps required to create a map.
We will use the State field from our Orders dataset, Sample - Superstore.xlsx
. Assuming that Tableau has identified our field as a geographical field and has generated the Latitude (generated) and Longitude (generated) fields, we will now proceed to create a map in Tableau.
Symbol map
.As mentioned previously, Tableau understands certain geographical roles.
The default logic in Tableau is that if the field name consists of common location names, such as country, state, city, zip code, post code, and so on, Tableau automatically identifies these fields as geographical fields. It will give these fields the previously discussed globe icon as a prefix and also automatically generate the Latitude (generated) and Longitude (generated) fields. The common location names identified by Tableau are typically the same as the geographical roles mentioned in the preceding link.
By default, Tableau will use the data from the online map provider. If we want to switch to the Offline mode, we can do so by selecting the Offline option from the Map | Background Maps menu.
In the case of the Offline maps, the image tiles that make up the map are stored in a cache along with our temporary Internet files. These temporary Internet files can be cleared manually at any time by simply deleting the temporary files from our browser. However, if we don't delete these manually, Tableau will clear them after about thirty days, after which it will then require us to reconnect and fetch an updated map. By doing this, Tableau makes sure that the map images that are being used don't become obsolete.
Apart from the default online and offline map options, Tableau also gives us the flexibility to use customized maps, by providing connectivity to either the Web Map Servers (WMS) or Mapbox Maps. This way, we can use custom maps, which can be specific to our industries. If we have access to a WMS provider or Mapbox maps, we can use these services by selecting either the WMS Servers… or the Mapbox Map… option by clicking on the Add button from Map | Background Maps | Map Services… in our toolbar.
To learn more about the usage of WMS Servers in Tableau, refer to http://onlinehelp.tableau.com/current/pro/desktop/en-us/maps_mapsources_wms.html.
To learn more about the usage of Mapbox Maps in Tableau, refer to http://onlinehelp.tableau.com/current/pro/desktop/en-us/maps_mapsources_mapbox.html.
As mentioned previously, Tableau reads the field name, and if it contains certain keywords such as state, city, country, zip code, and many more, and it will assume that the field is a geographical field. However, it may so happen that the field contains names of various cities, but the field name does not contain the word city in it. Instead it may be called, say, Location. In this case, Tableau will not consider this as a geographical field, and there won't be any Latitude (generated) and Longitude (generated) fields in the Measures pane. To convert this to a geographical field in order to create a map, we will have to assign a geographical role to the field. We can click on the dropdown or right-click on the field in the Dimensions pane and select the Geographic Role option, and then assign the relevant role. Refer to the following image:
Now, if we notice the Region field in our data, we will see the prefix Abc instead of the previously mentioned globe icon. This is because Tableau doesn't understand Region as a geographical role. However, if we wish to create a map from the Region field, we will have to right-click on the Region field in the Dimensions pane and select the Create from… | State option under Geographic Role. Refer to the following image:
Once we do that, the prefix of the Region field will change from Abc
to the globe icon similar to that of the State field or City field in the Dimensions pane. We can then use the Region field to create a map by simply getting the Latitude (generated) and Longitude (generated) fields in the Rows and Columns shelf, respectively. We can then drop the Region field from the Dimensions pane into the Color shelf, followed by dropping the Sales field from the Measures pane into the Text shelf. We can then convert the Symbol map to a Filled map by selecting the Filled Map option from the Marks dropdown. Refer to the following image:
The preceding functionality was introduced in Tableau 10 and is referred to as Custom Territories. The other way to create the Custom Territories is by creating Groups, a functionality that we will learn about in the next chapter.
Further, there may be times, when the default mapping functionality in Tableau won't suffice and we may want to go beyond the roles that are predefined in Tableau. For example, let's say we have data for a retail chain. This retail chain may have various outlets that are spread across multiple locations within cities across various countries. The default mapping of Tableau may not be able to plot these outlets on the map since it doesn't have the necessary geographical role predefined. In this case, we may have to refer to an external source for these geocodes.
To do so, we'll need to Import Custom Geocodes in Tableau by creating a .csv
file that contains the geocodes in the form of Latitude and Longitude. These Latitude and Longitude values will have to be stored as real numbers. This .csv
should ideally be stored in a separate dedicated folder.
To import the Custom Geocodes, we will have to click on Map | Geocoding | Import Custom Geocoding. Refer to the following image:
In this case, we will need to give the path of the folder which contains the .csv
file. However, there are a couple of points to remember when using this approach:
.csv
file must contain the Latitude and Longitude data.18.218.171.212