• Hex Map Spatial File

    I love hex maps! Especially for the United States, you can keep states in a basic geographic orientation, but eliminate the visual perception problems caused by the fact that some states are huge compared to others (and Alaska and Hawaii shift the scale when added).

    But there are a few headaches that can occur when creating and using hex maps.  Fortunately, there is a solution, which I believe offers the best of all worlds (and of course, I’ll include share download below!)…

    Some background on Hex Maps in Tableau

    Matt Chamber’s post on Hex Maps in Tableau inspired many with how easy it was to use custom shapes to create a hex map in Tableau.  And he inspired me to use one (for my first time) in the 2017 Iron Viz finals:

    IronViz - Joshua Milligan's Dashboard

    But, as Rody Zakovich noted, it is impossible to precisely control the size of custom shapes in Tableau.  And especially as you bring a view into a dashboard and adjust the size of the view, the size you had selected in the individual view probably isn’t right and you engage in a frustrating cycle of adjusting the size, returning to the dashboard, returning to the view and adjusting the size, …

    So, Rody came up with a brilliant alternative: use polygons.  In his blog post, Polygon Hex Map in Tableau, Rody demonstrates how to use a data set that defines a polygon hex shape for each state and then uses Tableau’s Polygon mark type to draw them.  This approach eliminates the sizing issue because Tableau does a great job of precisely adjusting the rendering of polygons based on the size of the view.

    But, polygons do have a couple of drawbacks:

    • They are very difficult to label (Alan Eldrige has a great post on why and a potential work-around)
    • The data set that defines them requires one record for every vertex of the polygon.  So each state will have six records.  This works well for blending, but joining is out of the question.

    A Spatial File Alternative

    One thing I love about the Tableau community is how we inspire each other!  Brittany Fong comes up with tile maps.  Matt uses the approach as one way of creating a hex map, it inspires me to use it and Rody to come up with another way.  And then I see Rody’s approach and think, “That’s incredible! But what if…”

    And as I thought about it, I realized that there is a feature in Tableau that might offer an alternative to polygons.  And it’s a relatively new feature, only released in 10.2: Spatial File Support.

    There is a lot you can do with spatial files that isn’t natively built in.  I mean, sure you can render the current counties of the United States, but what about showing counties as they looked 100 or 200 years ago?

    And what if you had a spatial file that rendered each state as a hexagon.  So, I grabbed Rody’s data set and ran it through Alteryx to generate a shape file (.shp).  Look at those amazing geospatial options:

    Alteryx Work Flow: Spatial File

    I had to adjust a bit for the map projection (and no, I didn’t use some fancy Euclidean geometry, I used trial and error!)  But in the end I had a spatial file that can be used in Tableau to render a hex map!

    And it shows great promise:

    • Labeling works beautifully!
    • You can blend or join! (because the spatial file has the whole polygon in a single geometry field – so there’s only one row per state)
    • It sizes perfectly as the view size changes.

    Here’ a hex map of the Zillow home value index using a blend on State

    Zillow Home Value Index Hex Map

    Thanks to Tableau’s cross database join, I can also join shape files other data sources:

    Hex States Join

    With an inner join, I might lose some states (Alaska and Hawaii do not exist in the Superstore demo data, so they won’t appear with an inner join, but a right join allow them to show up):

    Superstore Sales by Hex State - Join

    Sharing and Using the Spatial File

    Do you want to use the spatial file yourself?  Of course you do!  And you’re in luck, because here are the spatial files (and the Alteryx work flow if you want to make your own adjustments!)

    And a few notes on using it:

    • Just double click the Geometry field to have Tableau generate the hex map!
    • You’ll want to washout the map completely.  I didn’t even try to match up the data from Matt and Rody with anything close to sensible latitude or longitude numbers, so you’ll see the hex map drawn over Africa (I like to think it’s close to Null Island).  But, you won’t want to see the background map, so go to Map > Layers and wash it out:

    Map Layers Washout

    • You’ll also want to go to Map > Options and remove all the interactivity that doesn’t really make sense with

    Map Option - none

     

    And if this post inspires you to use hex maps or come up with a new approach of your own, I’d love to know!

     

    Post Tagged with , , ,

15 Responsesso far.

  1. Luisa says:

    Hi Joshua,

    This is awesome! Thanks for uploading this.
    Could you write a tutorial on how to create a spatial file in Alteryx? I would like to display the Indian states as spatial hex map. I do have the coordinates for the normal hex map, but I’m not sure how do feed it into Alteryx.

    Thanks,

    Luisa

    • Joshua Milligan says:

      Luisa,

      Thank you! That’s a great idea! I’ll give that some thought and let you know what I end up doing!

      • Luisa says:

        Sounds good!
        In the meantime, I have created an Excel file with Indian states for Tabelau’s polygon function. It works for my visualisation, but I’d like to know how you derived Y2, Y3, Y4, Y5, and Y6 for your shapefile.
        I can send you the file if it helps.

  2. Craig Dewar says:

    Hey Josh – just downloaded your shp file – makes hex maps so easy.
    Love it! Thanks

    • Joshua Milligan says:

      You’re welcome! Thanks for the feedback and I’m glad it helps!

      • Craig Dewar says:

        Hey Josh – just noted that the map showing in the background for me is Africa (lat,long 0,0). I see in your screenshots there is no map for you. Did you find out a way to get the hexes lat long to correspond roughly with USA backbround map?

  3. Bryan Hallock says:

    I found Hex U.S. Maps first from a NPR blog from May’15, which documents how they came to the idea from tiles to hexagons. They first used it in Apr’15. The Tableau users mentioned above came later, although Ben’s blog was a good “how to” and definitely inspired me.

    http://blog.apps.npr.org/2015/05/11/hex-tile-maps.html

    The spatial file solution looks interesting, my map is currently static.

  4. Al says:

    Hi,
    I double-click on Geometry and nothing happens, a map does not appear??

    • Al says:

      So I had a wrong join which I fixed and can now see the map. But, I am losing states when they are not in my join table. I’ve done the RIGHT join and am still losing them from the map.

      • Joshua Milligan says:

        Hmmm… a right join should work, but if you filter by anything from the left side, you might lose states.

  5. Melissa says:

    I love using hexmaps in Tableau and using spatial files looks like the best way to do it! Do you happen to have the spatial files for the US states that also include the US territories? Or know of a way to edit the files you do have to include the 5 US territories?

    • Joshua Milligan says:

      I don’t actually. However, I know that several individuals have taken this work and expanded upon it. Let me see if I can gather up a few resources.

  6. Oh my goodness, thank you Joshua!!! This worked beautifully for me. The hexagons look so clean and perfect, I love it. And it was so easy to join the spatial file, I couldn’t believe it! Thank you for taking the time to create and share this.

Leave a Reply

Your email address will not be published. Required fields are marked *