How do you create a background map for use in Tableau that only shows specific countries?
This is probably not a typical use case, but I did want to do this for a project last year where I was creating a MapTrix flow visualisation:
Notice that the UK, France, Portugal and other countries are not shown on the map. I only wanted to show the top 10 countries for which data was available.
Just use Map Layers?
When I created this visualisation, Map Layers were not yet released. That said, when I recreate a similar map with Map Layers using a small data set, while visually it looks the same (only a selection of countries are shown):
… if I select a mark, the country marks are greyed (as is normal behaviour), regardless of if it’s a separate data source or if ‘Disable Selection’ is set for the country map layer (as this is highlighting and not selection):
It is possible to work around this highlighting by adding another field to the view as described here, however, in some situations it’s nice to just have a fixed background that you know will not change regardless of the actions taken to marks in the view.
Filtering Countries in MapBox
This is where using a custom map can be helpful. It’s possible to filter data in MapBox Studio based on fields in data that you load into MapBox or fields available in the map layers available within MapBox. Here’s how…
Note, if you’ve not used MapBox before, take a look at this blog post first, which covers creating an account and getting started.
Create a new style based on the Blank template
Add a new layer and select “country_boundaries”.
Select a field to filter on. Here I’m using the “…alpha_3” field
Currently the filter criteria is set to “none”, so click “Add value”:
Enter a three letter country code, e.g. DEU (for Germany) and click “Use DEU” that appears at the bottom of that dialog box. It will then show as listed here:
Continue to add more countries as needed. The map will change colour to highlight which countries are filtered in (green) and out (maroon).
Finally, click the layer name on the left to close the layer configuration panel and only the filtered countries will show on the map as seen here. Optionally, change other formatting, such as colour – I changed the colour to blue:
You can then Publish the map (the button in the top right of the screen), and share it for use in Tableau – (again, see my earlier blog post for details).
Custom MapBox Map in Tableau
Add the map to Tableau using this menu option:
The map will then show in the view, and any marks in the view can then be selected or interacted with and the background map will not be affected in any way.
Add Data Points to a MapBox Map
It’s also possible to add data to a MapBox map and bring that into Tableau, so that it will also not be affected my user interaction. For example, you might want to show data marks in the background that is fixed, but then layer interactive marks on top of that – this blog post walks through an example:
Thanks for reading!
Latest YouTube video
This video tutorial steps through how to create a dot plot in Tableau.