Most people working with Tableau are aware of the possibility to create custom color palettes, as documented in this article by Tableau. We are able to create different types of palettes:
- Categorical: for assigning colors to discrete values.
- Sequential: for continuous values, typically one color that varies in intensity.
- Diverging: also for continuous values, usually using color intensity to show the magnitude of the number and the actual color to show which range the number is from.
What's interesting is that we can "manipulate" these color palettes for a few different purposes as well. An example:
Imagine we have data where we have certain values between 1 and 4. We want to color code these values as follows:
This does not necessarily require us to use custom color palettes. We can simply assign the colors to these values when they are discrete:
The default colors ...
... can be adapted ...
... to color code the values as we like:
Now, this all works fine when our data has all the values we want to assign a color to. When dealing with sparser data, this can form an issue. The same steps could turn out as follows:
The default values look like this ...
... and we assign our values as before.
This looks okay:
However, look at what happens when the data is updated and a new value appears:
You can see how this would form a problem. Then again, this is exactly what this post is about. We can circumvent this by using a custom, sequential color palette! We just need to be able to assign gray to both values 1 and 2, then fade into yellow for 3 and finally red for 4. This can be achieved with the following Preferences.tps file and color palette:
<color-palette name="Misc. 4 Step Sequential Gray-Red" type="ordered-sequential">
Now, let's assign our Value as a continuous color. Our new palette is available in the Edit Colors dialogue.
We can configure the range as we need. In case we don't have the minimum and maximum values in the data (yet), we can set the Start and End values to ensure correct assignment of the colors in our range.
Tada! The values look just as they're supposed to, colored from gray to red, over yellow.
As this is a continuous range of colors, we won't have the issue of unassigned values appearing in our data later on. And just because we can, look at all the crazy stuff we can do now!