Power BI Hex Map

5 mins read

Power BI is a powerful visual tool though sometimes when it comes to its mapping capabilities it can feel a bit limiting. David Eldersveld has some great reviews of mapping options in Power BI on his blog.

Geospatial techniques such as choropleth mapping can be easily achieved using the basic shape map visual (which seems to be in permanent preview) and you can import and use a variety of differing shape maps .

But when it comes to doing more than changing the shape and colour of your map, the basic Power BI shape map visual will not do the job.
In this post we will explore some of these restrictions and some of the techniques you can use to do more with your maps.

Shape Map Visual

Usually the shape map visual is used to produce choropleth maps ;maps shaded or colored in relation to a value, or symbol maps, which plot data at specific locations. Both techniques are useful and can easily be done in Power BI using the shape map visual.

But what if you would like to represent your data by the shape of your map locations rather than how they’re coloured or what shapes are being plotted on top of them, you to have access to a shape file with the type of shapes you want, Power BI will not manipulate your regular files to produce these kinds of maps.

For example, when it comes to plotting election data, maps with modified shapes such as hex maps are a lot better for the job because they normalise differences in geographical landmass sizes among political boundaries. By doing so they prevent one party being visually over-represented by the size of its constituency than the number of votes they had.

The maps above illustrate this; the conservative vote looks a lot bigger in the map on the left than it does on the hex map on the right. Donald Trump’s infamous “Impeach This” map is another good example of bad analysis here.

To avoid this over representation in our Power BI, we can provide provide the shape map visual with a custom shape map with normalised geographical regions.

In the example above we achieved this with the help of ODI Leeds, who created a UK constituencies hex map shape file (saved in the HexJSON file extention).

Though the ODI Leeds HexJSON is a valid shape file, it cannot be displayed in Power BI’s shape file visual as it only accepts TopoJSON shape files In-order to use it, we need to convert the HexJSON into TopoJSON. This can be achieved with Oli Hawkins handy HexJSON editor.

On the HexJSON editor web page you can upload your HexJSON and select some of the options shown in the images above, though the property label and category colour options can be ignored as these won’t work show up in the Power BI shape map visual as data will be used to colour the hexes. The padding of the hexes will be visible so set the padding between the hex shapes to a suitable value.

Once you’re happy with any changes you can download the map in the GeoJSON format.

With the hex map GeoJSON file ready all you need to do is convert it into a TopoJSON and it can be used in the Power BI shape map visual. Map shaper provides an excellent and easy to use tool for converting GeoJSON data into TopoJSON.

After converting your hex map shape into TopoJSON it can be uploaded into Power BI’s shape map visual and used to create informative choropleth maps such as the UK general elections one posted above.

The Power BI shape map visual won’t do anything beyond colouring your shapes and allowing you to plot symbols on top of them, so if you wanted to label your constituencies with their constituency code or any other text to help your viewers understand which constituency is which, you must use a custom visual.

Synoptic Panel

The synoptic panel visual can be found on the Power BI App Source, it allows you to connect your datasets to SVG files. Unlike the map shape visual, this visual allows you to both edit the colour of your geographical locations and display labels.

We created the labeled hex map above by making use of the SVG format found on the ODI Leeds Hex Map Project. This SVG file was then edited with a text editor, to remove the “hex-” prefix on the constituency IDs, which allowed us to link our data up to the SVG file once we uploaded it to the synoptic panel visual. (More detailed instructions are contained in the PowerBI report below).

At this point it was just a matter of colour coding the constituencies with the appropriate winning party colours and choosing the constituency ID column within our dataset to be used for the text on each constituency.

All in all Power BI does a decent job by providing us with a variety of ways to display our geographical data and both methods have their own pros and cons, these can be explored in the Power BI dashboard embedded below.

Icon Map

Since writing this post – a huge amount of changes have been made to James Dales’ Icon Map which is rapidly becoming THE map for anything other than simple pin or heat-maps. Recent changes include support for GeoJSON shapes including drill-down and labels. We will blog more about this soon.