We can visualize movements in Tableau by drawing lines between points. This takes advantage of the Line mark and the Path property.
In this recipe, we are going to visualize who Shaquille O'Neal played for from 1992 to 2011:
To follow this recipe, open B05527_05 – STARTER.twbx
. Use the worksheet called Using Path
, and connect to the Player Stats (NBA Players Regular Season 2009)
data source:
You will also need to download the team logos you would like to use (and, of course, check the term agreements to using these logos if you need to use these in public dashboards). Create a folder called NBA
in the Shapes folder, and place the icons in this folder:
Here are the steps to create the map with path lines:
ID
, Team Name
, From-To
, and # Years Label
.In this recipe, we visualized which teams Shaquille O'Neal played for. We represented the teams with the team logo, and drew lines between teams he moved from and to. These are two different marks; therefore, we needed to use a dual axis graph.
To show the teams using the team logo, we simply need to use the Shape mark type. Before this, we need to load the team logos into Tableau Repository's Shape folder:
If you create the folder and copy the icons while you have Tableau open, you will need to click Reload Shapes in the Edit Shapes window first before you can see it:
To draw the lines between the teams, we first need to change the mark type to Line. When we change the mark type to Line, a new property appears in the Marks card, which is Path:
To better understand what this Path property is for, we can start by understanding what the term path means. One of the definitions of path in www.dictionary.com is as follows:
A route, course, or track along which something moves
This is exactly what Path helps with—we are trying to visualize a route. In our recipe, we are trying to picture Shaq's movement from team to team. Since we want the movement to be influenced by when Shaq moved, we place the Year field onto Path. This, together with the Line mark type, draws the lines, in sequence, between the teams Shaq played for. For other use cases, a date, date/time, or sequence number can be placed onto this Path property to control where the lines go.
It is possible to calculate distance between locations in Tableau. To calculate distance, we need to have the source and destination latitude and longitude values in the same row. We can achieve this by either manipulating the data source so it already has it, or by performing a self join (that is, a table being joined to itself).
If the data source is Excel, we can do a self join if we connect to it using Legacy Connection:
Legacy Connection uses the Microsoft Jet Data Engine driver, which has since been replaced by Tableau.
The Legacy Connection option was introduced in Tableau 8.2. You can learn more about this in the Tableau KB article Differences between Legacy and Default Excel and Text File Connections, which can be found at http://bit.ly/tableau-legacy-jet.
Choosing Legacy Connection enables us to have a new option called New Custom SQL:
The self join query will look like the following code:
SELECT [Shaq$].[ID] AS [ID1], [Shaq$].[Team Name] AS [Team Name1], [Shaq$].[Latitude] AS [Latitude1], [Shaq$].[Longitude] AS [Longitude1], [Shaq2$].[ID] AS [ID2], [Shaq2$].[Team Name] AS [Team Name2], [Shaq2$].[Latitude] AS [Latitude2], [Shaq2$].[Longitude] AS [Longitude2] FROM [Shaq$] LEFT JOIN [Shaq$] [Shaq2$] ON ([Shaq$].[ID] = [Shaq2$].[ID] - 1)
Once the latitude and longitude values of the previous and next teams are in the same row, we can use the great-circle distance formula to calculate the distance. The great-circle distance has been defined in Wikipedia (https://en.wikipedia.org/wiki/Great-circle_distance) as follows:
The shortest distance between two points on the surface of a sphere, measured along the surface of the sphere (as opposed to a straight line through the sphere's interior)
The procedure for calculating the distance in Tableau is documented here - http://bit.ly/tableau-distance. The formula for the Tableau calculated field will look like this:
3959 * ACOS ( SIN(RADIANS([Latitude1])) * SIN(RADIANS([Latitude2])) + COS(RADIANS([Latitude1])) * COS(RADIANS([Latitude2])) * COS(RADIANS([Longitude2]) - RADIANS([Longitude1])) )
Once we have the distance values, we can utilize them on the maps:
One more tidbit about Tableau maps. If you zoom in enough and use the Radial Selection tool (the dashed circle icon) from the View Toolbar, you will be able to see the distance between two points. The limitation is this is fairly visual in nature and currently cannot be annotated or saved like a calculated field:
Please refer to the recipes in Chapter 7, Data Preparation
18.191.176.228