Inset Maps with Power BI Shape Maps

Inset maps – sometimes known as locator maps –  are small maps that sit alongside a main map and act provide context for the main map.  They are often used for example when a main map shows a close-up of a region, to show where that region sits within a larger area such as a county.

We can create Choropleth maps in Power BI which show zoomed in areas, with an inset map to place the main map in its wider context.  This blog post describes how I do it.

Choropleth maps or shape maps in Power BI use custom topojson maps files and I’m going to use two topojson files that I’ve already prepared for this example.  See this post on how to create topojson files for creating choropleth maps with the Shape map visual.

The dataset that this example is using is the police street crimes data set available from data.police.uk/data/. I am using a sub-set of the data for the Lancashire Police Force Area. The main map displays the street crime totals by LSOA.  In order to support basic exploration of the data I have enhanced the data model with a geography dimension or lookup that places each LSOA area within its respective Local Authority.  This enables filtering of the data by local authority to show only those LSOAs within the selected Local Authority.  To display the map on the report  I am using the Shape map visual.  In its default view, the map shows all the LSOAs in Lancashire as seen below.

While this is effective in the county context as it shows the whole area in  a single view with greater crime in the darker shades, some of the detail is lost because of the scale of the map.  It would be useful to show the data for each local authority in more detail and there are a couple of options to do this; one would be to create a map for each local authority, but this is time-consuming and not easy to display in Power BI (unless each Local Authority had its own report page for example); another option is to enable auto-zoom on the Shape map, so that when a filter on Local Authority is applied, the map zooms to the extent of the selected area.  This works nicely, but has the side effect of isolating the Local Authority from the wider county/police force area.

This is where the inset map comes in. By placing a second smaller map close to the main map, which shows all the local authorities in the Lancashire police force area, it is easy to relate the zoomed in extent of the main map to its highlighted counterpart in the inset map.   Furthermore, due to the cross-filtering support in Power BI the inset map can be used to drive the selection of the Local Authority and zoom in the main map. Nice!

This is how the main map looks zoomed in on Preston with the Preston local authority highlighted in the inset map.

 

Step by step guide

These are the steps required to create the above map

The following are required:

  • A data set containing the crime data for Lancashire
  • A geography dimension to allow grouping and filtering of the data into different hierarchical areas.  The data already includes the LSOA area, so we can use this to relate the crime data to the geography dimension which includes the hierarchy of areas such as LSOA – Local  Authority – Police Force Area.
  • A topojson map file  for the all the LSOAs in the Police Force Area (if you don’t know what this means, read this!)
  • A topojson map file for the Local Authorities in the Police Force Areas to use as the Inset Map.

You will have all the above pre-requisites if you read this post first

I’m assuming the Power BI file exists with the data loaded.  The rest of this post steps through the map creation.

On a new report page, add a Shape map. (If the Shape map visual is not available in the visuals pane, you may need to enable it from from Preview Features.  Click File – Options and Settings – Options, then select Preview Features and tick Shape map visual).

To the Location field property add the LSOA Code and to the Color saturation field property add the Total Crime measure (this is just a simple count of rows).  The default map of North America will display.  To change this to our LSOA map, click Format (paint roller) and click Shape to open up the Shape field well.  Click Add map, and select the LancashirePoliceForceAreaLSOAs.json file.

You should see the map display change to show the correct map.  You can style the map however you wish, but to follow the example I’ve used, open up the Data colors field well, enabled diverging, and set the Maximum, Center, and Minimum colours to use the Orange colour range where Maximum is the darkest shade, Center is the middle shade and Minimum is the lightest shade of orange.

You will notice that the map appears to be mostly a single shade of orange despite setting the colour range.  This is because the dataset is as yet un-filtered and there are some LSOAS in the country with some very crime totals.  To fix this add a filter to the filter pane for Police Force Area, which is in the geography dataset,  and filter on Lancashire.  You will notice a slight change to the shading on the map, as the map is setting its colour range over the range of crime totals only across Lancashire.  However its still not ideal.  This is because there are a few crime hotspots with very high crime totals. i.e. the data is not evenly distributed across the LSOAs.  You can see this if you add a bar chart to the page with LSOA Name on the axis and total crime for the value.  The vast majority of LSOAs have less than 50 reported crimes, but there are a few with many more with the max being 233.  So instead of allowing the visual to automatically scale colour range, we can manually set these values. (Be aware though that manual values may not accurately reflect the distribution of any new data that is added when the data is refreshed, so manual configuration would need monitoring in production).

For this example, I’ve set the maximum value as 100 (so any LSOAs with 100 or more crimes will be shaded in the darkest colour), and the Center colour as 20. You can experiment with these to see what works best for your data.  In general, if the data is normally distributed, then the defaults may work, but if your data is skewed as in this case, setting manual values is likely to work better, subject to the caveat about refreshed data.

In the Shape map Default color field well, change the background colour to white and the border colour to a pale grey (these settings help to make the inset map stand out when the main map is zoomed).

In the Zoom field well turn on Auto-zoom

Finally turn off the visual header.

Add the inset map

The procedure to add the inset map is similar to the main map.  Add a Shape map visual to the report but size it appropriately and position it to the top right of the main map (You can adjust these later, but get the general size and location approximately correct now).

To the Location field add Local Authority from the geography dataset.  We don’t need to add a value as we are not intending to use this map to aggregate and data.

From the Shape field well, add a custom map.  This time add the LancashirePoliceForceAreaLocalAuthorities.json file.

To style the inset map, set the data colour to something subdued, such as a mid-grey so as not to detract from the main map. Also set the default colour to light grey and the border to white. Add a border ( I like a grey border with a radius of 15), and turn off the visual header

Set the background to on, and set the transparency to about 30%.  This ensures that the inset map remains clearly visible but does not completely obscure any parts of the main map behind it (which can vary depending on what is selected).

Turn the title off (for one or both maps if desired), or set to something appropriate.  I prefer the inset map to have no title as its purpose should be obvious.

Some adjustment to position and size of both maps may be required, but the inset map can now be clicked to filter and zoom the main map while providing that all important higher level context.

Heres the finished report.  Click the bars or the inset map to see it in action! (Best viewed fullscreen)

Posted in GIS, Maps, Power BI.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.