28
Nov
2018
2

Tutorial – visualising data in Tableau with the RNLI

So far, we have looked at visualising Royal National Lifeboat Institute and Ordnance Survey data using QGIS and Kepler software. In this, our third technical blog, we will be using Tableau.

Tableau is a data visualisation software that is used for creating a wide range of different visualisation to interactively present data and obtain insights. It has a very intuitive user interface and you don’t need any coding knowledge to work with it. For this tutorial we will be using Tableau Public which can be downloaded here.

We will be creating a spider map or origin-destination map that shows paths between our origins (RNLI stations) and destinations (call-outs). All the data you will need for this tutorial can be found here.

Within this data folder there is a CSV file called tableau_finished which was created using a combination of the RNLI_Return_of_Service_20082006.csv and RNLI_Lifeboat_Station_Locations.csv.

There are several ways to create spider maps in Tableau and for the purpose of creating this map, our data source needed to contain the following information:

  • An ID that tells us if the row is the station or call-out
  • A Path ID for every unique path
  • Latitude and longitude coordinates for every location

For this type of spider map, there should also be two rows in your data source for each path. That means you should have one row for your origin location data and one row for your destination location data repeated for every path. This is a crucial step that enables Tableau to draw your paths correctly.

To understand this a little better let’s load the CSV file into Tableau

> Open Tableau and click on Text file

> Browse to the CSV file named tableau_finished > click Open

> In the window that has just opened you should be able to see your CSV files column headers but no data. To load some data, change the value in the rows box to 10

> Click Update Now

Within this table you can now see how our CSV is structured.

The Station column
For each unique path you want to create, you need a row for your origin location and a row for your destination location in your data source. This means your origin location will be paired with every destination location.

For example, when showing the path between an origin station location and several call-out destination locations, you need a row for the origin location and a row for the destination location for every single path.

In our CSV above, the origin station Aberdeen is paired with two different destination locations (ABERDEEN_100, ABERDEEN_10171) to show that for Aberdeen we have two different call-out locations. There is a column for Origin-Destination to further illustrate this concept, but this column is not required.

The Path ID column

The Path ID column is used to identify each unique origin-to-destination path. You will use this column to create your spider map.

For each origin and destination location, there is a unique key or string that identifies them as a pair.

In our CSV, for the first origin-destination path, the Path ID is ABERDEEN_100. For the second origin-destination path, the Path ID is ABERDEEN_10171. Each path ID is listed twice; once for the origin location and once for the destination location. As our destination location has no name, we generated a numerical field (100,10171 etc.) based on its row position within the CSV. We then used this value within the Station column for our destination name.

> Click on New Worksheet (found in the bottom left corner)

The first thing to do is visualise our point data from our CSV file onto a map. We do this using the longitude and latitude fields from our data.

> From the Measures box (bottom left) drag Longitude to the Columns shelf and Latitude to the Rows shelf

> On the Columns shelf, right-click the Longitude field and select Dimension

> On the Rows shelf do the same

This will make sure Tableau does not aggregate your origin and destination locations.

This is now showing us all the locations in the data source as points on our map. There is a data point for every RNLI station and call-out location.

By default Tableau uses OpenStreetMap as its backdrop mapping, but we can change this.

We recently announced details of the OS Open Zoomstack trial which gives users access to a comprehensive vector basemap showing coverage of Great Britain at a national level, right down to street level detail. This data can be served through Mapbox (an open source mapping platform for building custom designed maps) as vector tiles and this in turn can be read by Tableau. We have already created a map style using the OS Open Zoomstack vector tiles and this can be uploaded to your Mapbox account for use with this tutorial. If you do not have a Mapbox account, you will need to set one up and details on how to do this can be found here.

> Open Mapbox and click on Studio

> Click on Pick a template or upload a style

> Click on Upload

> The map style is called style2.json and can be found here

JSON is short for JavaScript Object Notation and is a way to store information in an organised, easy-to-access manner. In a nutshell, it gives us a human-readable collection of data that we can access in a logical manner.

> Open the file. The map style should now be visible in your Mapbox window and is called OS Outdoor-RNLI

> Next click on the back arrow next to your style header

> Click on the Menu button next to your style and click Make public

Now we have our map style loaded into Mapbox we can add it as our base map within Tableau.

> Click on Map from the top Tableau menu

> Select Background Maps > Map Services…

> In the Map Services box that appears click Add…

> Select Mapbox Maps…

We now need to populate the Url field with our Mapbox style URL

> Navigate back to your Mapbox account

> Click on Studio

> Next to your OS Outdoor_RNLI style click on Share & Use

> From the window that appears make sure your style is set to Public and click on Use

> From the menu on the left-hand side select Third party and then Tableau from the middle menu

> Copy the URL or use the clipboard button

> Navigate back to Tableau and paste the URL into the Url field. Give your style a name

> From the Map Services box click close

Your base map should now have changed to our OS Open Zoomstack data using the style we applied in Mapbox. Try navigating around the map using the pan and zoom functionality within Tableau.

> On the Marks card, click the Marks drop-down and select Line. Your data should update depicting a line connecting each data point. Looks a bit of a mess!

> From Dimension, drag Path ID to the Marks card

Your map view should now look something like the following.

Tableau uses the Path ID field to identify which points share a common attribute which in our case is the RNLI station. It then draws a line from this station point location to each of the call-out location points which share that common attribute.

Next, we can create a dynamic filter. This will allow us to select an individual station so only it and its call-out locations are visible in our map window.

The first thing we need to do is add another CSV file which we’ll use later.

> Click on the Tableau icon which can be found in the top left of your screen

> Click on Text file and browse to the location of our RNLI_Return_of_Service_20082006 CSV file > click Open

> Return to your Tableau worksheet by clicking on the worksheet found next to the Data Source box at the bottom left of your screen. This will probably be called Sheet 1 or Sheet 2. You can rename this if you wish by right-clicking and selecting Rename

> Make sure that under the Data pane you have tableau_finished highlighted as your data source

> From the Dimensions pane drop-down select Create Parameter…

> In the Create Parameter dialogue box, do the following:

  • Change the name to StationSelected.
  • Change Data type to String
  • For Allowable values, click List > select Add from Field
  • Select the CSV RNLI_Return_of_Service_20082016 > select the Lifeboat Station Name Proper
  • Click OK

> From the top Tableau menu select Analysis > Create Calculated Field

> In the calculation editor, name the calculated field Select by Origin-Destination

> Enter the following formula:

IF

LEFT([Path ID], FIND([Path ID], “_”) -1) = [StationSelected] THEN “Origin”

ELSEIF

RIGHT([Path ID], LEN([Path ID]) – FIND([Path ID], “_”)) = [StationSelected] THEN “Destination”

ELSE

“Unselected stations”

END

In the formula above, each Path ID (for example ABERDEEN_100) contains an underscore (_) as a delimiter to separate the origin location name (ABERDEEN) from the destination location name (100). This delimiter is used in the formula to tell Tableau which locations are origin locations, and which are destination locations.

> Make sure the calculation is valid, and click OK

> From Dimensions, drag the calculated field (Select by Origin-Destination) to the Filters shelf

> In the Filter dialogue box, Select Origin and then click OK

> Under Parameters click the StationSelected parameter drop-down

> Select Show Parameter Control

You will now be able to select an RNLI Station from the StationSelected drop-down on the right-hand side and the map window will update accordingly.

Next, we can start to look at adding some styling to our data to make it easier to interpret.

> Under the Marks card click on Size and reduce the width of your lines

> Click on Colour and under the Halo drop-down click None

Next, we are going to colour our lines based on one of the attributes within our data

> From Dimensions, drag the Casualty field to Colour on the Marks card

> Feel free to change the assigned colours by clicking on Colour within the Marks card and selecting Edit Colours… You can assign each colour manually or choose one of the Tableau palettes from the drop-down

> Under Colour change the opacity of your lines to 25% and make sure your lines markers are set to Automatic

Next, lets add a point to represent each of the call-out locations which will be colour coded to match our lines

> From the Measures box drag Longitude to the Columns shelf and Latitude to the Rows shelf. This is basically allowing us to visualise the point data from our data source twice

> Right click on Longitude (far right) > select Dimension > select Dual Axis

> Right click on Latitude (far right) > select Dimension > select Dual Axis

This tells Tableau this data is spatial and that we want it to appear on the same map

> Under your Marks card you should have a Latitude layer (our original line data) and Latitude(2) which at the moment is a direct duplication this layer

> Select Latitude(2) from the Marks card and change the drop-down to circle

> Increase the radius of your circles and change the opacity to 100%

Next, let’s add another filter based on the Outcome field within our data. This field allows us to visualise our data based on the outcome of each call and includes whether the call was a false alarm or not.

> From the Dimensions box drag Outcome to the Filters card

> From the Filter dialogue box select the data attributes that you would like available through the filter.

> Select OK

> Within the Filters card click on the Outcome filter drop-down and select Show Filter

Your Outcome filter should now be visible on the right-hand side of your page

> Turn it into a drop-down menu by clicking on the Outcome filter drop-down and selecting Single Value (dropdown)

You have made an interactive map based on Ordnance Survey’s OS Open Zoomstack and RNLI’s Station and call-out locations. The map allows you to zoom to each RNLI Station and view each of its call-outs which have been coloured based on the type of casualty associated with each call. Using another drop-down you are also able to filter your data further based on the outcome of each of the call-outs.

We can share this data by saving our worksheet to Tableau Public. This will give you a URL you are then able to share.

> Click File > Save to Tableau Public As…

Feel free to check out one of the GeoDataViz team’s version here.

> You can return to this map within Tableau at any point by opening Tableau > File > Open from Tableau Public

The GeoDataViz team at Ordnance Survey hope you found these three technical blog posts useful. Any feedback on this series would be appreciated as well as ideas for future technical blog posts. Please email them to cartodesign@os.uk.

We would like to say a big thank you to the RNLI for opening up these amazing datasets and to Tableau where some of the instructions for this blog were taken.

You may also like

Tutorial – visualising data in Kepler with the RNLI
Tutorial – visualising data in QGIS with the RNLI
Meet the team: Joe Harrison
OS Open Zoomstack trial so far

Leave a Reply

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

Name* :

Email* :

Website: