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.



Table view showing small multiples calculated using DIM field







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.




View without shifting the stems up


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:





Dim and Activity(Year) added into the view





Below, is an illustration of what we have done to place the flowers for each year in the flower layer:





We are essentially making use of relative positioning. Everything is relative to the red dot at the centre of the grey circle in the pic to the left.  This is the origin point. In our case (-[4 - Row],[5 - Col]). 


Please note that you may need to adjust the “shift factors” in C_Flowers a little in your viz to get the best fit for the flowers on the stem. For example change 0.35 to 0.3 or 0.15 to 0.2.  I encourage you to be patient with it and not be discouraged - See it as an opportunity to really get a deep understanding of the relative positioning concept.


Now let’s change the marks for YEAR(Activity Date) to Shape and apply our 3 flowers that we imported into our repository. Use a different flower for each year, and feel free to swap colors around as you please. I recommend sorting the years in the correct chronological order here as well.




 

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:






Things are looking pretty decent now so let’s add our symbols, labels and BAN’s.


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: 






Now lets add labels & BANS.  Drag SUM (Values) to the label mark and change the Dim field mark to a text mark. Change the label alignment to Bottom Center and the view should now be complete.  


Note – Don’t worry about the overlap in text, it isn’t going to look this way after it is published to TP.  However, if you want to, a trick I often use here is to alias the names to a shorter text that means the same thing as the original text, so it looks more balanced.




THE PROGRAMS SHEET 

These are the locations of each program where the outreach centres are located. We will build a view to show Sunny Streets activity in each program center. 
Create a new worksheet to use in creating the second view.


Now let’s create two fields:


F_PGM  
IF [Program] = "Fraser Coast" THEN 1
ELSEIF [Program] = "Gold Coast" THEN 2
ELSEIF [Program] = "Sunshine Coast" THEN 3
ELSEIF [Program] = "Brisbane" THEN 4
ELSE 5
END


This field creates a number for each program so we can build layers using the numbers.


G_Program
MAKEPOINT(0,[F_PGM])


This makes a point for each of the programs which we need in our layer.



Creating the View


Drop G_Program into the empty view and create a new layer like we’ve done before.  Note: I’ve put the Program field onto the filter to exclude COVID respiratory clinics because It has no interactions to show.


The previous ‘Dim’ filter which removes the “Shift Safety” and “Length Minutes” dimensions from the view, is also applied. Don’t forget to uncheck all the options under “Map” > “Map Layers” as described at the beginning of this blog post.  Change the mark to “circle”.  Now add the Program field onto the marks layer, and the Values field onto the size layer.  Increase the circle size to fit the size you want and change the color to grey or whatever you like
The view should look like what’s shown below:





Create a new field G_Program2 : MAKEPOINT(0.2,[F_PGM]). This creates the same layer as the previous one but places the marks a bit higher vertically to position the stem properly.


Grab G_Program2 onto the view to create another layer, change the mark to shapes, add the Program field to the marks, and then change the shape to the stem you imported into your repository. The same one that’s been used throughout. Increase the size to the maximum or whatever size you want.


Let's add the flowers(Years) into the view.

Create a calculated field PGM_Flowers

IF YEAR([Activity Date]) = 2019 THEN MAKEPOINT(0.3,[F_PGM]-0.15)
ELSEIF YEAR([Activity Date]) = 2020 THEN MAKEPOINT(0.45,[F_PGM]+0.1)
ELSEIF  YEAR([Activity Date]) = 2021 THEN MAKEPOINT(0.25,[F_PGM]+0.15)
END


Place it onto the view to create another new layer, and add Program onto the Detail card.  This field also uses relative positioning and you may need to adjust the shift factors ( 0.3, -0.15) etc to make the flowers sit properly on the stem.  
Add YEAR(Activity Date) to the marks pane to create a point for each year of activity for each of the program centers.  The view should look like what we have below:





Change the year marks to shape, and the flowers we set previously should show up automatically.  Finish off the view by adding Values onto the size marks and change the size based on how big you want the flowers to be.  These are how the fields should look on the marks pane:





The view should now look like this: 






Go back to the G_Program2 layer (Stem) and add Values to the text mark, then change the Program mark to label and change the font and size to what you like.


The Impact Section


Here we’ll need to add the Patient Data dataset to work with. It’s located in the sunny street folder with the rest of the data. For “The Impact” section of this viz, I’d encourage you to revisit the workbook as it can be easily replicated. It makes use of shapes to show the data. No map layers were used.





For the final portion titled Get Involved, we place a picture of the stem on the dashboard at the bottom right. You can use the one provided with the shapes at the beginning. We then create a worksheet for each flower and manually position at each point on the stem. Each flower is a worksheet which uses shapes to represent an action (learn more, donate, and volunteer).





After the view is built, we then use Dashboard URL Actions to enable the redirects to the url’s required to perform each of the actions. These are the links used:

Donate: mailto:info@sunnystreet.org (This just lets you send an email)


To create each action, Click Dashboard > Actions > Add Action > Go to Url and set up the actions how its shown below for each sheet:







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:

Powered by Blogger.