11/22/2020
Layering Mark Varieties in Tableau 2020.4
One of many new options in Tableau 2020.4 (at present in pre-release, however in all probability coming quickly since Tableau Public is already working it) is the flexibility to layer a number of shapefiles on prime of one another. This will probably be tremendous useful for maps, however we are able to additionally leverage this characteristic to layer a number of mark varieties on the canvas outdoors of maps. One in style technique to layer mark varieties is through the use of a twin axis. Nonetheless, we’re restricted to 2 marks in that case. On this weblog publish I’ll define how you should utilize this characteristic to layer marks for extra than simply maps.
To do that, we are going to leverage the generated latitude and longitude. And to try this we are going to use the MAKEPOINT perform in Tableau. As an alternative of utilizing a real latitude and longitude, we are going to substitute these with two measures.
So this is the trick. Usually longitude is positioned on the columns and latitude is positioned on the rows. When you reverse this format, Tableau plots a scatter plot. You’ll be able to do that out with the Superstore knowledge. Double-click Metropolis and Tableau will plot a map. Then click on the little icon on the highest to Swap the Rows and Columns (or CTRL-W) and Tableau will change the map to a scatter plot.
For this demonstration, I’m going to make use of the World Indicator knowledge set in Tableau. You’ll need to place your measures in a MAKEPOINT perform. Nonetheless, within the MAKEPOINT calculation, you’ll put the measure that you really want on the columns because the Latitude and the measure that you really want on the rows because the Longitude. That is backwards to our regular considering, however it’s because once we are carried out inserting the pilss we’re going to swap the fields (altering it from a map to a scatter plot). So, we construct the map, add the layers that we’d like and swap the rows and columns.
Let’s give it a go.
Step 1: Creating Calculated Fields for Measures
Step one is making a calculated discipline based mostly on the mesaures that you simply wish to use. On this viz, I will plot circles for a selected yr, however present a line for a ten yr pattern. To do that, I’ll solely plot the measures for the circles when the yr = 2010.
The 2 measures that I am plotting are Start Fee as Latitude and Life Expectancy as Longitude (the MAKEPOINT will truly plot coordinate techniques too, however that does not matter right here). We may even duplicate this calculated discipline for the Density mark.
Calculated Area: Circles
System: IF DATEPART(‘yr’, [Year]) = 2010 THEN MAKEPOINT([Birth Rate], [Life Expectancy Female]) END
Calculated Area: Density
System: IF DATEPART(‘yr’, [Year]) = 2010 THEN MAKEPOINT([Birth Rate], [Life Expectancy Female]) END
Subsequent, create a parameter for Nation Choice. This may enable us to make use of a Parameter Motion to hover over a rustic and present the ten yr pattern.
Parameter Identify: Nation Choice
Knowledge Sort: String
Allowable Values: Checklist
Add values from: Nation/Area
Calculated Area: Line for Nation Choice
System: IF [Country/Region] = [Country Selection] and DATEPART(‘yr’, [Year]) <=2010 THEN MAKEPOINT([Birth Rate], [Life Expectancy Female]) END
We now have three mark varieties that we’ll layer on the Tableau canvas in a scatter plot. Discover that the tablet varieties for these three calculated fields is a Geometry.
Step 2: Constructing the Viz
Double-click Circles to create a map. Longitude (generated) will go to the Columns and Latitude (generated) will go to the Rows and Circles will go to Particulars on the Marks Card as a COLLECT (plotting a map).
This subsequent step is vital. Drag the brand new calculated discipline Density over on to the canvas, however earlier than you drop it, you will note a Add a Marks Layer within the prime left hand nook of the map. Drop the sector in that field so as to add a brand new layer. A second Marks Card is created.
Repeat this step for the Line for Nation Choice discipline. Drag it on to the canvas and drop it within the Add a Marks Layer field within the prime left hand nook of the map. One other Marks Card is created. You’ll be able to repeat this as wanted to create further layers.
After getting the all of the layers that you simply want, merely click on on the little icon on the highest bar to Swap Rows and Columns (or just hit CTRL-W). You now have a scatter plot with three marks labels. Every Marks Card may be configured and formatted as wanted.
On the Circles Marks Card:
Change the dropdown field to Circles.
Drag Nation/Area to the Particulars on the Marks Card.
Drag Inhabitants Complete to the Dimension on the Marks Card.
Click on Coloration on the Marks Card and alter the colour to a lightweight grey, with 40% Opacity and a black Border coloration.
Modify the Dimension slider to make the circles larger.
On the Density Marks Card:
Change the dropdown field to Density.
Drag Nation/Area to the Particulars on the Marks Card.
Proper-click and Drag CO2 Emmissions to Coloration on the Marks Card and choose Common because the aggregation.
Click on Coloration on the Marks Card and alter the colour to Density Grey-Purple Gentle, with 93% Depth and 100% Opacity.
Modify the Dimension slider to make the circles larger.
Choose the down arrow on the appropriate of the Density Marks Card identify (the road above the dropdown possibility field) and choose « Transfer Down ». This selection permits you to transfer the mark up or down, altering the layering order, which is also called the Z-Order. See extra data on Z-Order on this weblog publish Z-Order in Tableau.
On the Line for Nation Marks Card:
Change the dropdown field to Line.
Drag Nation/Area to the Particulars on the Marks Card.
Proper-click on the NULL indicator within the backside proper hand nook and choose Disguise Indicator.
Drag 12 months to Path on the Marks Card.
Proper-Click on and drag 12 months to Dimension on the Marks Card and choose the primary YEAR(12 months) possibility for the date format.
Proper-Click on and drag 12 months to Label on the Marks Card and choose the primary YEAR(12 months) possibility for the date format.
Click on Label on the Marks Card and Choose Line Ends to solely present the labels for the primary and final yr.
You now have a scatter plot formatted with three totally different Mark varieties.
Step 3: Including Parameter Motion
Let’s add a Parameter Motion to Spotlight a Nation and add an extra mark layer for the nation label.
Choose « Worksheet » from the highest menu bar and choose « Actions… ».
Click on « Add Motion » and choose « Change Parameter… »
Choose « Run Motion on: » Hover
Within the Parameter dropdown choose Nation Choice
Within the Area dropdown choose Nation/Area
Click on OK and Okay.
Now while you hover over the international locations, the goal nation ought to have a ten yr pattern line displaying.
Step 3: Including Extra Layers
Including aadditional marks is pretty straight-forward. Create the calculated fields that your want. Then merely swap the Rows and Columns fields once more (CTRL-W), add your further mark and swap it again.
Let’s add an extra mark for the nation label as an illustration. First we have to create two extra calculated fields. The primary one will populate the Nation identify when it matches the parameter, which can up to date based mostly on the Hover motion. Second, a brand new MAKEPOINT calculation to hardcode the place of the label on the canvas.
Calculated Area: Nation Label
System: IF [Country Selection] = [Country/Region] THEN [Country/Region] END
Calculated Area: Nation Label Place
System: MAKEPOINT(.025,50)
Click on on the little icon on the highest bar to Swap Rows and Columns (or just hit CTRL-W) to swap it to a map view.
Drag the brand new Nation Label Place discipline on to the canvas and drop it within the Add a Marks Layer field within the prime left hand nook of the map. One other Marks Card is created.
Once more, click on on the little icon on the highest bar to Swap Rows and Columns (or just hit CTRL-W) to swap it again to a scatter plot.
On the brand new Nation Label Place Marks Card:
Drag Nation/Area to Label on the Marks Card.
Change the dropdown field to Textual content
Choose Dimension and drag the slider to make the textual content larger.
Choose Textual content to format the textual content as wanted.
If it is advisable add further marks, simply repeat these steps. Create a calculated discipline to plot the meassure or a set place. Swap the Rows and Columns to vary to a map view, add the extra layer and swap the Rows and Columns again to make it a scatter plot. Then format the brand new Marks Card as wanted.
Caveat: Luke Stanke identified that the generated latitude and longitude are bounded at 180 and -180. On this case, I used to be inside that vary, so it labored. Luke goes to jot down up a block publish on another technique that can assist you to prolong this vary for increased values. Within the meantime, this is what he is outlined that appeared to work nicely.
1) Add a geogrpahic discipline, like State to get the generated lat/lengthy. You’ll be able to create one if wanted.
3) Add this discipline for extra layers. Actually, add just a few further since you will not have the ability to add extra later, and you’ll all the time take away them.
4) Take away the generated lat/lengthy from Columns and Rows.
5) Duplicate every measure and set the geogrpahic property to latitude or longitude.
6) add them to the Columns and Rows (Latitude to Columns and Longitude to Rows so that you simply get a scatter plot).
7) Take away the geographic discipline from the Marks card.