0% found this document useful (0 votes)
96 views

Data Visualization - Day 3 - in Class Exercises - Geospatial Graphs - Solution Final

The document discusses creating correlation and geospatial graphs in Tableau using various data sets. It provides step-by-step instructions on how to create a correlation graph showing the relationship between fertility rate and life expectancy over time for different countries. It also describes how to create basic symbol maps in Tableau using country-level data and customize the maps with different styles, layers and data. Finally, it demonstrates how to create more advanced maps, including multiple maps showing categories and segments, a dual-axis map, and maps using background images.

Uploaded by

Ghulam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Data Visualization - Day 3 - in Class Exercises - Geospatial Graphs - Solution Final

The document discusses creating correlation and geospatial graphs in Tableau using various data sets. It provides step-by-step instructions on how to create a correlation graph showing the relationship between fertility rate and life expectancy over time for different countries. It also describes how to create basic symbol maps in Tableau using country-level data and customize the maps with different styles, layers and data. Finally, it demonstrates how to create more advanced maps, including multiple maps showing categories and segments, a dual-axis map, and maps using background images.

Uploaded by

Ghulam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

ITOM 6212 Data Visualization and Communication

ICE - Day 3 – Correlation and Geospatial Graphs


Exercise 1: Correlation
Correlation shows a relationship or connection between two or more things. In Hans Rosling’s diagram, he showed
the correlation between Fertility Rate and Life Expectancy for different countries over the years to see how they
changed over time. Let’s re-create his chart.

First start with blending the data in Alteryx.

Input Fertility Rate and Life Expectancy data and Run each.

Notice how the data is configured. We will need to adjust the data to use it in Tableau.

Start by Transposing the Data so that Country Name, Country Code, Year and Value are the Columns – do this by
making Country Name and Country Code the Key Fields and the Years are Data Fields.

1
Use the Select tool to change the Name field to Year in both. Change the Value field in the Fertility Rate file to
Fertility Rate and the Value field in the Life Expectancy file to Life Expectancy.

Join the data based on Country Code, Country Name and Year.

2
Input Population Data.

Use the Select tool to change Year to String 4

3
Join the Population data to the Fertility and Life Expectancy data by Country Code, Country Name and Year.

Load Region Data.

4
Join Region Data by Country Name and Country Code – make sure to join Country Name to County. Be sure to
uncheck Country and Country Name in the right.

Output the data to Tableau. Call it DV ICE 3 Correlation.

5
Using the DV ICE 3 Correlation Tableau file, load the data into Tableau.

Let’s create the chart with Life Expectancy on the Y Axis and Fertility Rate on the X Axis.

6
We will want to change the Data from SUM to DIMENSION for both Life Expectancy and Fertility Rate.

Let’s Add Year to Pages – this will allow us to look at one year at a time and move from year to year.

7
Now Size your bubbles by Population and Color them by Region and increase the Size of the bubbles so they can
easily be seen.

As per Hans Rosling, we are going to use 30 as the start year or Life Expectancy.

8
Let’s adjust the colors for each Region:

North America and South America – Blue

Asia and Oceana – Red

Latin America – Dark Green

Africa – Light Green

Australia – Purple

Arabic – Yellow

Europe – Brown

9
Now let’s color in the bubbles by changing the Mark to Circles – but move the transparency to 50% and add a
border.

And finally, let’s add a filter by Country Cod and change the format of Year to no commas.

10
Now we can run this using the Pages we created. Change the speed to fast and push the forward button.

I could also ook at this for a specific country – let’s try the US, IND and China

11
Call this Correlation

12
Exercise 2: Geospatial Graphs - Mapping and Images
In a display that features where quantitative values are located, the relationship is primarily special. Most special
relationships feature the geographic location of values by displaying them on a map. A typical example is a map
that displays how many cases of a particular disease occurred in each country throughout the world. Spatial
relationships are not limited to geography, however. For example, someone who managed environmental
conditions (e.g., air temperature) throughout a large, multi-story building, might want a geographical display that
positions values on a floor plan of the building. Because non-geographical special displays of quantitative data are
rare, we focus on geospatial displays. Words that indicate a geospatial relationship include:
• Geography
• Location
• Where
• Region
• Territory
• Country
• State
• City

Basic Mapping
Connect to the GSS and Bob’s data you created in Alteryx. In this exercise you will create basic symbol maps, learn
how to change the map style, learn how to add different layers such as map layers and data layers, learn how to
use size and color to analyze your data, learn how to create filled maps, what a small multiples map is, and how to
create a dual axis map.
Exercise 1: Create a Basic Symbol Map:

Create a basic global map of the Superstore Data using Country as the mapping element.

Now let’s apply different map styles to the map you just created.

13
Change the Map style to Normal and add the Coastline to your Map.

If I go to the Map menu and select Map Layers (options prior to 9.2), I can change the style to what I want. The
default style is Light, but in this case, I’ll change it to Normal. Then click on the Coastline to add it to the map.

Add the most recent census data to your map. Add US Population Male Age (median) data.

14
Call this Census Map.
We can add other map styles to Tableau. Tableau also supports connections to web map services (WMS), as well
as connections to Mapbox maps.
Mapbox lets you to create your own custom background maps or connect to ready-to-use base maps. In
order to use Mapbox you need to create an account at Mapbox.com. This will provide you with an access
token. You need this access token to use Mapbox. Once you have the token, you can go to Map-
>Background Maps->Map Services.

15
To get the token, go to https://www.mapbox.com/ and create an account.
For this exercise, we can use the public token
pk.eyJ1IjoiaHRhYm9yMDEiLCJhIjoiY2lpdWxrbmdwMDAyYnVia250bHRsdGt5byJ9.Pe40fqLCI9aHNEffUsZguw

Click on Add->Mapbox maps

Click on Classic, Name your style (I name it the same as theirs, e.g. Light and enter the API Access Code

16
Add the ones you want and later you can bring them up when you are doing a map.

17
You can also use other Web Map Services (MWS) that are available. Some are available for free. One of the most
interesting is the NASA Mapping. To use this, you Add a WMS Mapping Service and enter the NASA WMS URL:
http://neowms.sci.gsfc.nasa.gov/wms/wms?

18
Then when you change the Map you can look at various Map Layers from NASA.

One of the most interesting is Blue Marble – make sure to unselect one map layer before adding another.

Let’s create another map and show the profit data for each country where each country is colored by the profit.

19
Call this Profitability Map.

Create a new Map to show Profit by color but using Circles (not a filled map). Then make the circles sized by sales.
Increase the size as necessary to be able to read it on the map.

Call this Circle Map

20
Multiples Maps
Create a new map by country. Make this a filled map and color it by Profit.

Show multiple versions of this map using Product Category and Product Segment. Which country has the highest
profit in the Consumer Segment and the Furniture Category? That would be China.

Call this Multiple Maps

21
Dual Axis Map
Create a map using the Country field. Make this a filled map, colored by Market.

Now let’s create a second map by clicking on Latitude in the Rows area and holding down the Control Key and
dragging it to the right.

Change the bottom map and change the Type from Filled to Pie Chart.

22
Change Color to show Product Category (to show the pie by Category) and size it by Sales – increase the size to
make it easier to read and add a border.

Now combine the 2 maps by making them a Dual Axis Map.

23
Lighten the color on the filled map by making it more transparent so you can better see the pie charts.

Call this Dual Map

24
Background Images
In Tableau, you can bring in background images and plot data against those images as a background map.
To begin, you’ll want to select the background image of your choice. We will use two background images. The first
one is the first floor of a hospital building and the second one is the second floor of that same building.

In this example, we’ll be finding the dimensions of the image just for clarity of demonstration. However, it should
be noted that you don’t need the image’s exact X and Y dimensional size. We just right click on the image, select

25
properties or file info, and under the details tab you’ll see those dimensions. We can record these dimensions or
any range of dimensions in an Excel workbook. Remember, you can enter any range of values that you want. So,
for simplicity we’ll just say that X goes from 0 to 668 and Y goes from 0 to 550.

Now let’s save the workbook and call is Hospital Coordinates so you can connect to it with Tableau. If you have a
map of the US for example and your image has specific latitude and longitude coordinates, you can choose which
latitude and longitude your image starts at and ends at. Likewise if your image has specific ranges as specified in
your data and your map, you can choose to enter those dimensions.

26
Once we’ve saved our workbook, we can actually connect to it in Tableau. Add a new data source (Hospital
Coordinates).

Now that we’ve connected to the workbook, let’s go to the map menu, select background images, and then the
data source that contains the dimensions you entered for that image. Choose add image and then browse to the
location of that image.

27
We’ll enter the dimensions for that image again. We’ll switch this to be the respective Y field, then select OK. At
any time, we can add or remove more images if we want to. Make sure to change the X Field to X and ut the
coordinates in the Right field.

Next, we’ll want to plot our X and Y fields. Drag X to the column shelf and Y to the row shelf. Let’s right click on
each axis to uncheck show header. And let’s name this sheet Hospital.

28
Now that we’ve imported the image, we can plot some points on it. To plot points on the image, simply right click
on any point, select annotate, and then point. Let’s start with the Sports Medicine Department. Right Click on it
and select annotate and point. Select ok, and you should see the X and Y coordinates for that point.

29
We can do this as many times as we want. Let’s also do this for

Now that we have the coordinates for each of these points, let’s go ahead and enter them in the workbook we
just created. You must create a column that identifies what each of these coordinates represents. The first set of
coordinates belongs to the entire image, so I’ll just call that the Ground Floor. Let’s also add a column that
indicates the Floor. Receiving and Nutrition Service.

30
Add these coordinates to the excel file Hospital Coordinates. Add a floor as well and call it 1 st. Add the Room.

Go ahead and save that workbook and then right click on the data source to refresh it.

31
Since we refreshed it, we must now place that room field on the level of detail shelf. Tableau is aggregating all the
values in the X and Y axes right now. By placing room on the level of detail, Tableau will now aggregate the X and Y
values by room, the lowest granular detail. We can see a mark for every single point plotted.

We can also remove the annotations by right clicking on them and selecting remove. We can also change the mark
type.

32
We can change the points to a Circle and Size it and Color it to see the and add Room to Labels.

33
Because this hospital is a multi-story building, we want to show data about the other floor as well.

To do that, let’s bring in another background image. We’ll follow the same steps as before and this time enter a
range of dimensions for the second image in the same workbook. I’ll just go ahead and reuse the same coordinates
I used for the first image. I’ll also identify this as the second floor. In addition, we want to identify each room on
each floor by which floor it belongs to. So let’s go ahead and create a new column and call it floor. I’ll label the first
floor 1st and the second floor 2nd.

34
When we do that, we’re going to overlay the first image with the second image. But what we really want to see is
an individual floor at a single time.

35
To enable that, we need to create a filter which allows a user to select which image they see at a given moment.

To create that filter, go back to the map menu, select background images, the image data source, and then select
the first image. Select edit, the options tab, and then add. Chose the field you want to filter by, in this case floor
and then select OK. We’re going to select first for the value because the ground floor belongs to the first floor. This
means when a user selects first, they will only see the ground floor image. Make sure you have refreshed your
data if the 2nd floor does not show on the list.

36
Let’s select OK, and repeat this for the second image. This time we’ll select second, so the user only sees the
second floor image when they select second.

We’ll go ahead and drag floor to the level of detail shelf and then right click on it to show the quick filter. We want
to change this to be a single value list, so let’s click on the drop down menu on the quick filter and change it to be a
single value list. We also want to get rid of the option to show all images at once, so we’ll select the drop down list,
customize, and then uncheck show all value. The user can now toggle back and forth between each floor of the
hospital.

37
Now that we’ve plotted our second image, let’s annotate some points on it. Note that you can just drag the
annotation to other parts of the image to find those coordinates. Let’s save the workbook and refresh the data
source. Let’s also remove the annotation on the image. You may have noticed a placeholder mark in the upper
right hand corner with the coordinates at the top of this image. It’s possible to change the dimensions of this
image within the data source at time, or delete that data from the data source to remove that mark. So there you
go, we’ve shown you how to import an image, how to use the image as a background map by annotating points on
it, and how to use filters to allow users to switch back and forth between different images on the same sheet.

38
39
You can use filters to toggle back and forth between different background images on the same view.

40
41
Exercise 3: Custom Geocoding and Paths
Custom Geocoding
We have a file that contains the names and addresses of some fake SMU Students (Student Address List). This is
an excel file. We want to use custom geocoding to determine the latitude and longitude of the addresses we have
been given. Using the batch geocoding web site https://www.mapdevelopers.com/batch_geocode_tool.php

To determine the latitude and longitude and map the students based on those latitudes and longitudes. Use the
web site to determine latitude and longitude from the student list.

42
Add the Latitude and Longitude to the file

Now let’s map this in Tableau.

Go to Tableau and Add a Data Source – and add the Student Address List with the new Latitude and Longitude.

43
In the new sheet, Plot latitude and longitude by dragging the latitude (NOT GENERATED) to the rows and longitude
(NOT GENERATED) – Change them to dimensions on the column and row lines.

Color and Size by GPA (Red Green Diverging) and put a black border around the circles; Add Name to the Detail.
Add City and GPA to the Labels. Change the GPA to Percentage with no decimal places. Call this Custom Geocode.

44
Paths
We want to mark the paths of our students from their current residence to SMU. The address and latitude and
longitude at SMU is

6212 Bishop Blvd Dallas Texas 75275 32.842177 -96.78367

In Tableau, you can create mapping to show a path between 2 points. This kind of path analysis requires a specific
data structure and uses the Path shelf.

Set up the data source - To create a view that shows the path between two points in Tableau Desktop, you need to
first make sure your data source has the right data structure.

Name Path ID Path Order Latitude Longitude GPA


ST201400000266 ST201400000266 to SMU 1 43.761154 -79.408838 .80
SMU ST201400000266 to SMU 2 32.842177 -96.78367
ST201400000041 ST201400000041 to SMU 1 31.229861 121.459989 .75
SMU ST201400000041 to SMU 2 32.842177 -96.78367
ST201400000151 ST201400000151 to SMU 1 31.229861 121.459989 .90
SMU ST201400000151 to SMU 2 32.842177 -96.78367

a. Create two rows of data for each path you want to trace. These rows can be referred to as the
"From" row and the "To" row. For example, when showing the path of a delivery from Student
ST201400000266 to SMU, you need a row for SMU and a row for Student ST201400000266.
b. For each data pair, create a unique key that identifies them as a pair. In this example, there is a
column called Path ID. For the two ST201400000266 to SMU, the Path ID is ST201400000266 to
SMU.

45
c. Create a column to define the path order, or the direction in which the line is drawn. For
example, the row for Student ST201400000266 has a path order of 1 and the row for SMU has a
path order of 2, which indicates that the path was from the Students location to the SMU.
d. Create a column to define the GPA amount. This can later be used to determine the size of the
lines.
e. Make sure to add a latitude column and a longitude column for each location in your data
source. 

1. Create the Path Data in Alteryx

We need to create a file like this for our students. We will create this in Alteryx.

a. Start by bringing in the Student Address list that now has the Latitude and Longitude you added
in the previous exercise.

b. Add a Text Input for Path with a Value of 1

46
c. Append the new Path to the Address File, but let’s only bring in the Name (Student Name), GPA
and Latitude and Longitude and the new Path field.

d. Add a Text file for the SMU Path with the fields Name (SMU); Latitude (32.842177), Longitude (-
96.78367), and Path Order (2)

47
e. Now we want to add the Path ID. Let’s create a Formula for Path ID where Path ID (new field) is
Name (Student Name) “ to SMU”

f. Append the SMU Text File we created to the Path Data we just created but remove the Target
data (except for the Path ID) and Rename the Source data

48
g. Do a Union of the Path Data and the SMU Path.

h. Create an Output file (Tableau format) called Student to SMU Paths.

49
Save this Alteryx Workbook as SMU to Student Paths Alteryx.

2. Plot the Path in Tableau


a. Add the new Students to SMU Paths Tableau file to Tableau.

50
b. From Measures, drag Longitude (NOT GENERATED) to the Columns shelf and Latitude (NOT
GENERATED) to the Rows shelf.
c. On the shelves, right-click Longitude and Latitude, and then select Dimension.

d. On the Marks card, click the Marks Type drop-down list, and then select Line. The view will
update to show a line connecting each mark.

51
e. To separate the marks into From-To pairs, add your unique key field to Detail on the Marks card.
In this example, the Path ID field is used. The view now shows lines from the ship from area to all
the other cities listed in the data sources.

f. From Measures, drag Path Order to the Path shelf. The field will automatically aggregate to the
sum of Path Order. Note: If you are trying to see a path over time (such as for weather patterns),
you can place the Date field on the Path shelf instead.

52
g. On the Marks card, right-click SUM (Path Order) and select Dimension. The field remains green,
but is now a dimension, meaning it is no longer being aggregated as a sum.

h. From Measures, drag GPA to Size and Color (color using Red Green Diverging). Add the GPA to
the label and format it to Percentage (no decimal places). Change the layout to Normal.

53
i. Call this Paths

54

You might also like