Guest Blog Post: Map Layers of Sunny Street by Chimdi Nwosu
The following is a guest blog post from Chimdi Nwosu. Chimdi is a Data Visualization Manager at Postmedia Network Inc. in Canada. He is a Tableau Ambassador and enjoys constantly experimenting with different visualization styles and techniques by leveraging Tableau in combination with other tools. Although Chimdi was far too humble to mention it himself, he had a huge year in 2021 and won four Tableau Vizzie awards (which tied him for the most ever in a single year). Ken and I are excited to have him as a guest blogger on FlerlageTwins.com. You can follow Chimdi on Twitter @menscuriosa or LinkedIn.
Introduction
This article explores building custom visuals using Tableau’s map layer functionality.
We illustrate this by unpacking the exact steps used to create my Sunny Street Viz (shown below) that I created for #VizForSocialGood. All the necessary tools to follow along are available. Note that the linked version is a replication of the original which was created to ensure that it lined up perfectly with this blog post.
About the Viz
Sunny Street provides healthcare to homeless and vulnerable people in Australia via mobile outreach clinics. Our goal with this viz is to visualize their activity and impact.
We’re provided details of their activity in the datafile, and descriptions are provided in the data dictionary given as part of the data package.
It highlights metrics like: Time of shift, length in minutes, number or referrals, shift safety rating, number of conversations about mental health, substance use, and more.
Volunteers can choose to visualize all the metrics, or some and so for this one, “Shift Safety” and “Length in Minutes” were excluded in the visual.
The Visualization is shown below:
Using Map layers in Tableau involves placing objects layered on top of one another within a single view. We expand on this by placing multiple objects within the same map layer in different locations defined by the creator.
This can come in handy when there are similar objects which we might want to work with as a group - It saves us from having to create a single layer for each one, making things easier to manage, especially if we have lots of layers to work with.
Here is some setup and prep If you’ll be following along:
The data and resources provided by Viz for Social Good can be found here. You can also go here to the project page, scroll down till you see the ‘Data’ button and then click it.
Here are some shapes I created which you can download and use as you replicate. Import these into your tableau repository before you begin - https://drive.google.com/drive/folders/1paPAkeY_x26KhBBlzaQIFCHRWjE4Y2ZI?usp=sharing.
This tutorial assumes you have a working knowledge of Tableau even if it’s at a basic level.
Before building a map layer in any view, we will have to get rid of the default map layers so click “map” then “layers” and uncheck all the options so we have a blank canvas to work with. Please do this for each new sheet you create.
THE INTERACTIONS SHEET
DATA
The key thing to note with the data is that we need to pivot the dimensions and values into single columns as shown below in the two highlighted columns. (For more information on pivoting, check out 3 Ways to Pivot in Tableau).
THE GRID SETUP
First we are going to layout the grid used in the viz which is shown below:
The foundation for the grid is the small multiples calculation.We’ll first create this view then use it to develop our “Rows” and “Columns” fields for the map layers.
Use a parameter to ensure we get a 5 x 3 grid
Create a “Grid” parameter with these settings:
1 – Grid:
The foundation for the grid is the small multiples calculation. We’ll first create this view then use it to develop our “Rows” and “Columns” fields for the map layers.
Next we create 2 calculated fields to create the grid.
This modified version of the original small multiple calculation gives us control over the grid.
For example, in the above setting, we force the grid to be R x 5 where R = number of rows and 5 = number of columns. Say we had 4 in the ‘current value’ above, it will create an R x 4 grid i.e., 4 columns and however many rows are needed to exhaust the available dimensions.
The result would be a grid with 4 columns and 4 rows, but the 4th row would have only 3 dimensions since we are only showing 15 dimensions total. i.e., 4 columns x 3 rows = 12 therefore the last row will show the remaining 3.
These are the fields we need to create here:
2 – Rows:
int((index()-1)/(round([Grid])))
3 – Columns:
(index ()-1)%(round([Grid]))
Now we can build the view and sort our dimensions how we want them to be shown.
The Makepoint function is the foundation of using map layers to develop non-map charts in Tableau. If you’re not familiar with how this all works, this blog by Jeffery Shaffer does a great job of explaining. Now may be a good time to review it before continuing with this one.
Hopefully you’re a little more familiar with Makepoint.
Keep in mind, we are not building yet, and the main reason is that the Makepoint(X,Y) function cannot take these 2 fields as input because they are table calculations. It only takes numbers as input for the values of X and Y.
Now let’s progress by building the view below using our fields. Place 2 - Rows on the rows shelf and 3 - Columns on the columns shelf. For this table calculation, click the small arrow beside 2 - Row and 3 - Column fields then click “compute using” then click Dim (picture shown below). Change the marks to circle or whatever you like - at this point, the shape isn’t relevant.
NOTE: The ‘Dim’ filter removes the “Shift Safety” and “Length Minutes” dimensions from the view. However, there is no reason not to show these if you feel like it. Personally, I created a “Shift Hours” field to replace the “length minutes” field and ignored the “Shift Safety” field.
The “Dim” field is sorted by choosing Sort by “Field” then choosing “ Value” and selecting descending as shown below:
NOTE: The ‘Dim’ filter removes the “Shift Safety” and “Length Minutes” dimensions from the view. However, there is no reason not to show these if you feel like it. Personally, I created a “Shift Hours” field to replace the “length minutes” field and ignored the “Shift Safety” field.
The “Dim” field is sorted by choosing Sort by “Field” then choosing “ Value” and selecting descending as shown below. The values and dimension names are placed on the label marks so we can check to see that the view is exactly how we’d like it to be.
THE ACTUAL VIEW
With everything we’ve done up to this point, we can now begin to create the fields to use in our map layers. Create two fields as follows:
4 – Row
IF [Dim] IN ("Patient Conversations","Conversations about health education","Mental health","Service provider conversations","Nursing/Paramedic Consults") THEN 0
ELSEIF [Dim] IN ("Length hours","Referrals (Formal and informal)","Medication education","Substance use", "Medical Consults") THEN 1
ELSE 2
END
5 – Col
IF [Dim] IN ("Patient Conversations","Referrals (Formal and informal)","Allied Health") THEN 0
ELSEIF [Dim] IN("Conversations about health education", "Medication education", "Suicide prevention/planning") THEN 1
ELSEIF [Dim] IN("Mental health", "Length hours", "Telehealth consults that happened at Clinic") THEN 2
ELSEIF [Dim] IN("Service provider conversations", "Substance use", "Nurse Practitioner Consults") THEN 3
ELSE 4
END
Logic:
If the Dimension is in “Row 0” in the grid pic above, then 0.
If the Dimension is in “Row 1” in the grid pic above, then 1, and so on…
The “Patient Conversations” is shifted up higher by setting it at -0.1 rather than 0 like the others.
Same logic applies for the Columns. i.e., If it is in Col 0 then 0 and so on.
Now let’s check to see what we’ve done by building the view using our new “5 - Col” and “4 - Row” fields.
THE MAP LAYERS
First we’ll create a layer to place the base circles into the view and size them based on the number of interactions. Create a calculated field as follows:
A _ Base Circles
MAKEPOINT(-[4 - Row],[5 - Col])
The minus sign reverses the row axes because if we maintain the natural axis then our bottom row (2) shows at the top and the top row (0) shows at the bottom. Technically you can fix this by setting the rows in our first pic of the grid, as Row 2, Row 1, and Row 0 respectively (rather than 0, 1, 2). However, I personally found it bothersome to remember to count numbers in reverse order as I built the layers. The minus sign was an easier fix.You can also just use ([4 - Row],[ 5 - Col]) and manually reverse the axis.
Now build the view below using relevant fields. Note that the long and lat fields are generated automatically by dropping the “Base circles” field into the view. We can then add the other fields manually.
You may have to adjust the sizes of the circles a little to make them fit the view. Now we have our first layer! Let’s carry on.
B_ Stem
Let’s create a calculation to make a layer which helps position the flower stems on top of the bottom circles.
Create a new field and type this formula: MAKEPOINT(-[4 - Row] + 0.25,[5 - Col]). The 0.25 Shifts the stem upwards in the view for placement on top of the base circles. (We’ll illustrate a bit more in a few moments). Drag the new field in the view until you see the “Add a marks layer” as shown below.
Add the field Dim to the view. Change the marks to “Shape” then apply the stem shape you imported into your repository. You should now see something like what’s shown below:
Add the field “Measure Names” to the “color” mark and change the color to green or whatever color you want the stem to be.
To demonstrate what’s happening by shifting the stem up a little, the view below shows what we’d get if we don’t add the 0.25 to the “Row” in the calculation. Notice how the stems sit right at the center of the circles. The “+0.25” shifts it up a little for a better view. -0.25 would shift it downwards rather than up. Feel free to play around with this number if you like.
C_Flowers
Now we’ll create a layer that places the flowers onto the stem. This is the fun part as it allows us to use a single calculation to place the flowers in 3 different positions on the stem, based on the year. The data has year values 2019, 2020 and 2021 in it.
Create a calculated field as follows:
IIF YEAR([Activity Date]) = 2019 THEN MAKEPOINT(-[4 - Row]+0.35,[5 - Col]-0.15)
ELSEIF YEAR([Activity Date]) = 2020 THEN MAKEPOINT(-[4 - Row]+0.5,[5 - Col]+0.1)
ELSE MAKEPOINT(-[4 - Row]+0.3,[5 - Col]+0.15)
END
In a few moments, we’ll dig deeper into what the “shift factors” ie. the +0.35, -0.15 etc are doing in this calculation.
Add a new layer and build the view below - start by dragging C_Flowers into the view as we did for the previous layer.
Add Dim and YEAR (Activity Date) to the view like the picture below.
Adding this allows us to have flowers for the metrics in each dimension, for the years within the dataset. For example - We’ll end up with different flowers for patient conversations in 2019, 2020, and 2021 respectively. The C_Flowers calculation places the flowers on the stem at the defined positions.
Add a new layer to the view:
Now grab the “Values” field and place it on the “size” marks to size the flowers according to the number of consultations, conversations etc. (You may need to resize the stems a little to make them proportional). We should see something like this:
D_Base Symbols
We’ll create a layer to set the type for each dimension i.e conversation consultation or metric. This is based on the sunny street activity carried out in the mobile outreach centers. Refer back to the data dictionary once more if this isn’t too clear.
Create a calculated field as follows: MAKEPOINT(-[4 - Row]-0.15,[5 - Col])
Create another field called E_Type as follows:
IF [Dim] IN ("Allied Health", "Medical Consults", "Nurse Practitioner Consults", "Nursing/Paramedic Consults", "Telehealth consults that happened at Clinic") THEN "Consult"
ELSEIF [Dim] IN ("Length hours", "Patients turned away", "Referrals (Formal and informal)") THEN "Metric"
ELSE "Conversation"
END
This assigns a type to each activity carried out in the centers.
Create new layers by dragging the field called D_Base Symbols into the view. Change the marks to shape and drag the field Dim into the view. Now let’s set the type of interaction (consultation, conversation, etc.). Drag the field E_Type into the marks pane and change the mark to shape. Click on the shapes mark to edit the shapes to whatever symbols you like. You can also adjust the color to whatever you like. The shapes I used are shown below:
The view should now look like what’s shown below:
At this point, we’ve covered all aspects of this viz and I’d like to thank you if you’ve made it this far.
I hope you had some fun here and have learnt enough to create your own ideas using layers. Please feel free to connect with me on twitter with any questions.
Thanks,
Chimdi
Kevin Flerlage, January 24, 2022
Twitter | LinkedIn | Tableau Public
No comments: