Custom Geocoding a Tile Map

NOTE: This blog post was originally going to be published on 3/08/2022. Thank you to Duy Nguyen and Chimdi Nwosu for the previous reviews and edits. Also check out the recent work by Klaus Schulte on this topic.

A tile map is one of the visualization I teach in my Tableau training workshops as it is fairly easy to make and it showcases a number of features in Tableau. As a map, it also has a number of benefits. For example, it avoids encoding values based on the size of land an area has. For U.S. maps, it also solves the placement issue of Alaska and Hawaii, and DC, without exlcuding them from the map. In this blog post, I will walk you through a method of quickly making a tile map, specifically a Hex Map, using Custom Geocoding in Tableau.

First, download the Hex Map Data Set.

Data Set: Hex Map Data

1. Create a Hex Map Folder

You will need to create a seperate folder to store the data file you are going to use for the hex map. So create a folder with the name Hex Map and move the downloaded file into this folder.

2. Modify CSV file

The field names and order matter. Make sure your geographic field (in this case State) is the first column followed by the latitude and longitude. NOTE - Additonal columns are fine, but they won't be used in the Custom Gecoding process (ex. state abbreviation). Order and spelling matter. The header names must be spelled correctly for Tableau to recognize them.

3. Import File

In Tableau, select Map from the top menu, and select Geocoding and then Import Custom Geocoding. Select the folder that you created with the file in it. Tableau will then generate a custom geocode file and save it in your Tableau Repository.

4. Change Field Property

Once Tableau has created the Custom Geocoding and saved it in your Tableau Repository, then it is now available to use in any visualization. You simply need to assign a geographic field to the new Custom Geocoding to use it and then Tableau will automatically plot that field using the new goecoding. In this example, we used State to map a custom geocoding position. Therefore, any dataset that has State in it can be used to do this. Simply right-click on State in any data source and set the geographic property to the new custom geocoding field.

5. Plot a Hex Map

Double-click that same field and Tableau will plot a hex map on top of a map layer. Remove map layer (100% opacity or uncheck boxes). Select desired hex shape and adjust size as needed. You will now have a hex map made by custom geocoding in Tableau.

Note that the use case of this technique is not to use the hex map CSV as data source, but as a template only. It means that you bring in any data sources with location fields (Provine/State/City) and other metrics. Then with this Geocoding technique, you can plot the same map and easily make it hex shapes.

Show Abbreviation

The one major drawback of using this technique is that you cannot add labels to custom geocoding, which was the main reason I never published this blog post. Even if the file has an abbreviation field, there is no way to put it on the view. One way to solve this is to use a calculated field. You could also leverage the Case Statement Generator from Kevin Flerlage to create this.

  Calculated Field: State Abbreviation
   CASE [State]
   WHEN 'Alabama' THEN 'AL'
   WHEN 'Alaska' THEN 'AK'
   WHEN 'Arizona' THEN 'AZ'
   WHEN 'Arkansas' THEN 'AR'
   WHEN 'California' THEN 'CA'
   WHEN 'Colorado' THEN 'CO'
   WHEN 'Connecticut' THEN 'CT'
   WHEN 'Delaware' THEN 'DE'
   WHEN 'Florida' THEN 'FL'
   WHEN 'Georgia' THEN 'GA'
   WHEN 'Hawaii' THEN 'HI'
   WHEN 'Idaho' THEN 'ID'
   WHEN 'Illinois' THEN 'IL'
   WHEN 'Indiana' THEN 'IN'
   WHEN 'Iowa' THEN 'IA'
   WHEN 'Kansas' THEN 'KS'
   WHEN 'Kentucky' THEN 'KY'
   WHEN 'Louisiana' THEN 'LA'
   WHEN 'Maine' THEN 'ME'
   WHEN 'Maryland' THEN 'MD'
   WHEN 'Massachusetts' THEN 'MA'
   WHEN 'Michigan' THEN 'MI'
   WHEN 'Minnesota' THEN 'MN'
   WHEN 'Mississippi' THEN 'MS'
   WHEN 'Missouri' THEN 'MO'
   WHEN 'Montana' THEN 'MT'
   WHEN 'Nebraska' THEN 'NE'
   WHEN 'Nevada' THEN 'NV'
   WHEN 'New Hampshire' THEN 'NH'
   WHEN 'New Jersey' THEN 'NJ'
   WHEN 'New Mexico' THEN 'NM'
   WHEN 'New York' THEN 'NY'
   WHEN 'North Carolina' THEN 'NC'
   WHEN 'North Dakota' THEN 'ND'
   WHEN 'Ohio' THEN 'OH'
   WHEN 'Oklahoma' THEN 'OK'
   WHEN 'Oregon' THEN 'OR'
   WHEN 'Pennsylvania' THEN 'PA'
   WHEN 'Rhode Island' THEN 'RI'
   WHEN 'South Carolina' THEN 'SC'
   WHEN 'South Dakota' THEN 'SD'
   WHEN 'Tennessee' THEN 'TN'
   WHEN 'Texas' THEN 'TX'
   WHEN 'Utah' THEN 'UT'
   WHEN 'Vermont' THEN 'VT'
   WHEN 'Virginia' THEN 'VA'
   WHEN 'Washington' THEN 'WA'
   WHEN 'West Virginia' THEN 'WV'
   WHEN 'Wisconsin' THEN 'WI'
   WHEN 'Wyoming' THEN 'WY'

Drag Abbreviation to Labels and adjust the text alignment and size as needed.
Below is a viz created by one of my students Duy Nguyen using this custom geocoding method and a hex map of Vietnam.

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

Jeffrey A. Shaffer

Follow on Twitter @HighVizAbility