Ads Top

3 Ways to Create Predominance Maps in Tableau


The US election ended a few months back, which means we’re seeing lots of predominance maps showing the election results. Whether you know the term or not, you’re probably very familiar with predominance maps. In simple terms, a predominance map uses to color to encode two pieces of information—who “won” and by how much? (For a detailed explanation, see ArcGIS: What is a Predominance Map?)


Let’s look at an example. Below is the Alabama 2016 presidential vote by county:


Counties which voted majority Republican are red and counties which voted majority Democrat are blue. But this type of map only tells part of the story—who won. It can be misleading because it doesn’t actually show the differential in each county. For example, Winston County went 90% to 8.5% in favor of Republicans while Conecuh County went 52% to 47% in favor of Republicans. Yet, both counties show the same red color on the map. Fortunately, we can address this flaw by adding some color gradients to the map so that we have shades of blue and shades of red.


The lighter the shade, the lower the margin of victory, the darker the shade the higher the margin of victory. This now tells us a much different story than the previous map. We can see where the race was close and where it was a blowout.

Unfortunately, it’s not entirely straightforward to create predominance maps in Tableau because they require you to essentially use two separate continuous color palettes. So, in this blog, I’ll share three different methods for creating them.

Quick Note on the Data: For this blog, I’ll be looking at the 2016 Presidential election and will be using a data set created by Tony McGovern. The data source has one column for Republican vote % (Percent Republican), another for Democrat vote % (Percent Democrat), and one showing the difference (Percent Difference Positive). Note: The difference field is always positive. I’ve also created a calculated field called Base Color which determines whether the base color should be Red (Republican win) or Blue (Democrat win).


Difference Bins
For the first method, we want to color by both the base color and by the percent difference. But Tableau will not allow us to color by a discrete field (Base Color) and continuous field (Percent Difference Positive). It will, however, allow us to color based on two discrete fields. We could turn Percent Difference Positive into a discrete field, but then when we assign color based on that, we’ll get a separate color for every single difference percent. We don’t want that so, instead, we’ll use bins.

1) Start out by building a basic filled map and coloring each county by the winner.


2) Create bins on the Percent Difference Positive field and pick a bin size that makes sense for your data. I’ve chosen 0.05 (or 5%):


3) Drag Percent Difference Positive (bins) to the Detail card, then click on the icon to the left of the pill and change it to Color (if we drag it directly to Color, it will replace the Base Color pill and we don’t want that). We now have two discrete fields controlling the color. Tableau is pretty intelligent here and assigns a range of color shades to each combination of base color and percent difference bin.


4) But, we want different colors, so click on the Color card to edit the colors. Manually select all of the blue colors, then select the Blue color palette and click Assign Palette.


5) Do the same thing for red colors, using the Red color palette.


Diverging Palette
The second method is to use a diverging palette.

1) We’ll use the same base map as we created in step 1 above.

2) Our percent difference field is always positive, so we’ll create another one, called simply Difference, that subtracts Percent Republican from Percent Democrat. So, when Democrats win, the value will be positive and when Republicans win, the value will be negative.

3) Drag Difference to the Color card, then click the Color card to edit the palette.

4) Select the Red-Blue Diverging palette.


Dual Axis Map
Our final method involves use of a dual axis map.

1) Again, we’ll use the same base map.

2) Duplicate either the Latitude or Longitude pill in order to create a second axis.

3) On the new axis, drag Percent Difference Positive to the color card. You’ll now have something like this.


4) We’re going to overlay the second axis over top of the first. The colors will blend to create the effect we’re looking for. For this to work properly, we want the continuous palette to go from white (hex FFFFFF)to black (hex 000000). Since this is not a default palette, we’ll need to create a custom one. (I won’t go into detail about how to create custom palettes, but if you’re unfamiliar with the process, see Create Custom Color Palettes.)

5) Assign the palette to the second axis.

6) Change the color opacity to a somewhat low value (I’m using 33%.) We’ll now have something like this:


6) Finally, change to a dual axis.


Which is Best?
So, which one should you use? Like all such questions, it depends. Each option has its own strengths and weaknesses:

Diverging Palette – This is the simplest method, but it has one serious limitation as it only works when there are exactly two competing entities. In the case of US elections, this is fine, but it won’t work for countries that do not have a two-party system.

Dual Axis – This method is fairly simple and very flexible—it can handle as many competing entities as your data requires. But, as you can see in the image above, this method distorts the color, which could create problems.

Bins – This method is able to handle multiple competing entities and does not distort the color. But it requires some manual work, which could eventually break down. And, most importantly, the bins won't always break up into nice chunks as in our example. These gaps can cause your colors to be applied inaccurately. 

As always, it comes down to your use case and requirements. So, before creating a map like this, think through all of these details before deciding on your approach.

Thanks for reading! If you use any of these methods to create a predominance map, I’d love to see the result.

Ken Flerlage, April 6, 2019

No comments:

Powered by Blogger.