How To Make Two Different Color Filters Tableau Map
Dorsum in 2014 I was inspired by this New York Times post The Most Detailed Maps You lot'll See from the Midterm Elections to try to figure out how to replicate those maps in Tableau. The maps essentially uses three color palettes on the same map, blue for Democratic leaning areas, scarlet for Republican, and purple for tossups where the lightness (relative low-cal/nighttime) of each color palette is based on the population of the precinct. And then nosotros might think of this in Tableau as coloring by a dimension (really a discrete value) of red/blue/regal so shading that by a measure (the population), however that's not something bachelor in a couple of clicks.
This post covers a multifariousness of techniques to build such a map, to simplify for this post we'll build this map where there are two color palettes
For this instance the data set up is Superstore Sales with some filters practical to create more than variation. A set of states have been arbitrarily grouped as Scarlet and another set as Blue, and the goal is to shade them inside the Red and Blue hues by the % of Total Sales. I added some additional requirements:
- The lightness of the colors in each palette must be equivalent (symmetrical) and then the "darkest" color in each color ramp corresponds to the highest % of Total Sales regardless of which hue the color is (carmine or blue). This allows the user to compare the relative lightness across the hues, if we don't and so then the visualization will atomic number 82 to inaccurate conclusions.
- The color ramps for the palettes must automatically update as the data changes, for example if a user filters the view or new data arrives.
- The colour legends themselves have to exist accurate and appear in the worksheet. This is an ease-of-structure requirement considering if we've used a technique that hacks the colour legends too much then we'd have to manually build a colour legend and put that in a dashboard.
- We demand flexibility with the color palettes then they can look every bit skilful (equally vibrant) as we want.
- The method needs to support at to the lowest degree one additional palette, for case if this were used in a US election prediction map to be able to use a unmarried tertiary hue for a truthful tossup state, or as in the NYTimes post to add an additional regal sequential palette to identify precincts that voted shut to fifty-l.
I tried several dissimilar methods, the simply method that satisfies all the requirements is the 6th ane. The six methods are:
- A calculated field that makes bluish negative and cherry-red positive and then a diverging palette based on that field. Trouble: The color ramps are non symmetrical and the colour legend would have to be manually created.
- Using a custom color palette (come across my post An Exploration of Custom Color Palettes) with calculated fields to normalize the values and properly assign the colors in the palette. This enables the lightness to be equivalent and dynamically updates with the data then it's really shut to the requirements and could piece of work in some situations. Problem: This requires more effort setting upwardly the color palettes and calculations and the colour legends would have to be manually created.
- A dual centrality map with background color and foreground as a sequential black palette with transparency. I get-go learned about this technique from Wil Jones of Interworks in Create a Dual Centrality Color Map in Tableau. Problem: The colors are also muted.
- Calculated field that returns discrete values and then manual consignment of colors. Problem: Colors are limited to the values that announced in the data, in this example the data is sparse so at that place'south no Red half-dozen-8. then if the information changes the palette won't automatically update (Tableau will assign the default palette) and and will need transmission effort.
- A dual centrality map with calculations that are used to change the level of detail of each Marks Carte past returning red states or blue states that have a geographic role assigned, then separate measures are available for each. This is getting shut because it gets united states of america completely separate palettes that can have the colors that nosotros desire. Trouble: To go on the shading of each colour palette the aforementioned the colour ramps had to be fixed at x%, so if the data changes the ramps will need to exist edited to reverberate the data or they could be misleading.
- This starts out similar to method #v: A dual axis map with calculations that are used to alter the level of item of each Marks Card by returning red states or blueish states that have a geographic role assigned, and then separate measures are available for each. In addition a indistinguishable State dimension that is not a geography is used to increase the level of particular so the color calculations can take aforementioned ramp of values. Problem: Most complicated to prepare, and tin can have bigger queries (which aren't a big deal when we're only looking at fifty states), but information technology'southward totally dynamic and meets all the requirements.
Here's how to build method #6:
Part ane: Dual axis maps at different levels of detail
- Make sure you take in your data a field that will group u.s.. In my case I built a map of the 50 states and grouped the states by manually selecting some and creating an ad hoc group that I chosen Country (group). If there'south a dimension value that tin can slice us this will also piece of work, or even a calculated field that creates a dimension.
- Create two calculated dimensions for Red States and Bluish States. Here's the Ruddy States formula:
IF [Land (group)] = 'Red' And so [State] END
. This only returns the state value so Nix for everything else. Also note the ability to apply ad hoc groups in calculations is new in version 10.0, if you're using an before version of Tableau you'd need to use a calculated field or field from the information source equally a dimension in the calc. - Assign the Red/Bluish States dimensions to the State geographic role.
- Create a filled map with the Red States dimension on the level of detail.
- Ctrl+elevate (Cmd+drag on Mac) the Latitude (generated) pill on Rows to the right to create a second centrality (and a third marks card, so there's All and 2 Latitude (generated) cards).
- Activate the bottom Marks card by clicking on the the right-hand Latitude (generated) pill on Rows.
- On the bottom marks carte supplant the Cerise States dimension with the Blue States dimension. You lot should now see a view like this:
What nosotros've washed hither is to create a dual axis map with two different levels of detail where the two Marks Cards for this map accept different dimensions. The upper map has the level of detail of Cherry States that includes all the states in the Red group plus one Zero value for all the blueish states, the lower map has the level of detail of Blue States that includes all u.s.a. in the Bluish group plus one Null value for all the carmine states.
Now at this point we could put separate % of total measures on the two Marks Cards with a Compute Using on the Cherry/Blue state, respectively and put those on the Color Shelf. This is method #five before nosotros've fixed the colors:
However this has 2 issues:
- Each Marks Card has a Null value (for blueish states on the Blood-red map and red states on the blue Map) that rolls up all those opposing states and ends up being the biggest % of Total and that affects the color ramp so the color range isn't as big as it could be. Note how the largest blue value is 36.88%, only the map is entirely light blue. We can workaround this past using the filter option on the null/unknown marks indicator in the lower correct, withal…
- The two color ramps are not symmetrical at the summit stop in terms of lightness/darkness and the simply style here to brand them symmetrical is to manually fix the color ramps, which then doesn't meet the requirement to have the view automatically update.
While can manually ready the bottom end of the color ramps at 0 to make them symmetrical there, at the top end we really need to accept the % of total measures return the aforementioned values and so that way nosotros don't have to manually fix the color ramps. That leads to the next steps in Part two.
Part two: Increment the level of particular without increasing the # of visible marks
I played effectually with a agglomeration of ideas on how to fix the trouble including doing a linear scaling, nesting table calculations, precomputing all the values so I wouldn't need to use tabular array calculations, and so on, until I came back to revisiting how Tableau's color ramp is determined for sequential palettes. The default is that bottom stop of the ramp is assigned to the lowest value of the field on the Color shelf and top end of the ramp is assigned to the highest value of the field on Color. The challenge with the approach and so far is that in each of the Reddish & Blueish color ramps there's a % of total value (the Null value for the blue states & ruddy states, respectively) that is being calculated merely is not visible. And that led to my insight: "Why not enable Tableau to have an accurate gear up of values for the color ramp that aren't visible?" and a few clicks afterwards I had it.
This solution leans on a couple of $.25 of somewhat esoteric Tableau knowledge:
a) In maps the visible marks are the ones that take an assigned geography. In this case for simply a subset of states have an assigned geography when the Cerise States dimension is used on one Marks card and a dissimilar subset has an assigned geography when the Bluish States dimension is used on the other Marks carte. So we've already seen that there tin exist boosted marks in the view that aren't visible, therefore nosotros can have all the states available on each marks bill of fare by adding a State dimension that isn't drawn as a geography.
b) Tabular array calcs have some interesting (to me, at to the lowest degree) behavior when in that location are multiple marks cards at different grains of detail the table adding results depend on what Marks card(s) the tabular array calculation is on. If a table calculation is on a single Marks carte then only the dimensions from that Marks card plus Rows, Columns, and Pages are available for addressing and partitioning. If a table adding is on the All Marks card so information technology tin use any of the dimensions anywhere for addressing and segmentation, however the table adding is separately computed for each Marks bill of fare based on the dimensions available for each Marks carte i.east. the dimensions on that Marks card + Rows, Columns, and Pages, and dimensions that are not on that particular Marks card are ignored. That's a lot of words, someday it'll have to be another post to go into more item.
In this case to get the % of full table calculation to the return the same result beyond both the scarlet state and blue state Marks cards we need to fix the addressing of the calculation so it is across all the State dimensions that nosotros are using – the State dimension that volition get an authentic % of total plus the Red and Blue States dimensions that are used to create visible marks.
Here'due south how to build information technology starting from Part ane in a higher place:
- Indistinguishable the State dimension.
- Remove the Country geographic office from the State (copy) dimension that you created in step 1 by right-clicking on the State (copy) dimension in the Dimensions window and choosing Geographic Role->None:
This is necessary so when nosotros add the the new Land (copy) dimension to the view that Tableau doesn't describe all united states of america on both the red & blue Marks cards. - Click on the All Marks card header to activate it.
- Add the State (copy) dimension to the Detail on the All Marks menu. Pro tip – you can drag it onto the Detail button or whatsoever part of the open up area in the bottom of the Marks card. You should run across a view that looks similar this:
Annotation the "27 unknown" in the lower correct, that's the sign that the level of detail has increased without making more states visible. If you lot see all the states in each map and so you'll need to re-do step two. - Nosotros demand to build three calculations to brand the colors. The commencement is a bog-standard % of total adding, nosotros can practice that entirely with drag & drop. Start past dragging Sales from Measures to the Detail on the All Marks carte.
- Right-click on the Sales pill on the Marks card and choose Quick Tabular array Adding->Pct of Full.
- Right-click on the Sales pill once again and choose Edit Table Calculation… to open the Table Adding window.
- Make sure Specific Dimensions is selected with all iii State dimensions clicked on: Red States, Blue States, and State (copy). Validate that the tabular array calculation is accurate past hovering over the marks, using View Data, etc.
- Drag the Sales pill from the Particular back to the Measures window. Tableau creates a new calculated field and gives you a hazard to name it, I called it % of Total Sales.
- Now to build out the measures that will exist used on Color. Right-click on the new % of Total Sales measure out and chose Create->Calculated Field… to create a new calculated field.
- Set the name of the new calculated field to be Red % of Total Sales, then click Apply.
- Repeat step 10.
- Set the name of this new calculated field to exist Bluish % of Total Sales, then click Apply.
- Drag both the Red & Blue % of Full Sales measures onto the All Marks bill of fare. The All Marks card should now wait like this:
- Actuate the red state Marks carte du jour by either clicking on its header or clicking on the appropriate Latitude (generated) pill.
- Click to the left of the Red % of Full pill to put it on Color. The view should now look like this:
- Hover over the colour legend and click on the drop-down menu->Edit Colors… to open up the color palette.
- Change the palette to Tableau's default Red sequential palette.
- Click on Avant-garde >> to open the avant-garde section.
- Click on the Start checkbox and enter 0. This is to ensure that both color palettes beginning from the same value.
- Click OK. The map should now expect like this:
- Activate the blue state Marks Card.
- Click to the left of the Blue % of Total pill to put information technology on Color. Annotation that both color legends have the same ending value.
- Hover over the colour legend and click on the drop-down menu->Edit Colors… to open the color palette.
- Click on Advanced >> to open the advanced section.
- Click on the Start checkbox and enter 0. This is to ensure that both color palettes showtime from the aforementioned value.
- Click OK. The map should now await like this:
- The last step in building the map is to right-click on the correct-hand Latitude (generated) pill on Rows and cull Dual Axis. Here's the map:
From here we tin can clean upwardly the map formatting, edit the tooltips, turn off the unknown indicator, etc.
Notes and Side by side Steps
A key function of what makes the colors more accurate is that Tableau's default scarlet & blue color palettes use the aforementioned lightness throughout the palettes. If y'all are going to use a different fix of palettes then take some fourth dimension to brand sure the lightness values are equivalent for the palettes.
If what distinguishes betwixt the states is a measure out (as opposed to a dimension like the advert hoc group used hither) and so you lot'll need to use a variation on this technique, if you have questions post below in the comments.
If you lot desire to go an additional discrete colour (such every bit to marking tossup states) then you tin can change the measure that draws colors for a given Marks card to return a single negative value and utilise a diverging palette with more configuration of the Avant-garde >> options, for example I've ready upwards Minnesota to be yellowish in this view:
If you're careful with sequential or diverging palettes you tin can actually make multiple continuous ranges and/or discrete colors in the same palette, come across An Exploration of Custom Color Palettes and Keith Helfrich'due south mail service at http://redheadedstepdata.io/color-the-dupes/ for more details. So either method #6 or method #2 could build something similar the NYTimes viz that I linked to at the start of this mail, the question is how much mucking effectually with color palettes and color legends do y'all desire to do?
Here's a link to the Ii Sequential Palettes on a Map workbook on Tableau Public.
If you think this is awesome and want more than y'all then please check out DataBlick, we provide Tableau grooming and consulting and even short-term back up to help you make better views and dashboards.
How To Make Two Different Color Filters Tableau Map,
Source: http://drawingwithnumbers.artisart.org/two-sequential-color-palettes-on-the-same-map/
Posted by: thompsonmorpegir.blogspot.com
0 Response to "How To Make Two Different Color Filters Tableau Map"
Post a Comment