Menu

Color The Tips

cover-image

Here we look at one of the nicer technique at Quantcast, coloring the tips for bars that extend beyond the reference line, and how to do this in Tableau. Coloring the tips of your bars so provides an instant, pre-cognitive call-out to over-indexing.

Example Data Set

Building upon yet another earlier analysis, in this example I work with SFPD Police Incidents Data.

To follow along, you can either export the most recent 3 months from data.sfgov.org (build your viz from scratch), or download the packaged workbook (review the finished product).

Over-Indexing is for Sample to Population Comparisons

Just as with the demographics data at Quantcast, our analysis of Police Incidents in San Francisco is also focused on the over-indexing of a sample observation, compared to a reference line for the population.

Quantcast looks at visitors to a given website (the sample), compared to all Internet users (the population). Here I highlight incident categories where the frequency in a given District (the sample) is greater than the average across the entire city (the population).

You can of course color the tips in any scenario where reference lines are used. For example, in a plan-to-actuals comparison for finance data. When doing so, please consider carefully whether over-shooting the reference line is the primary focus of your message?

Pre-req Know-How

Robin Kennedy’s post from the Information Lab titled maintain percent of total in Tableau when using filters is profoundly useful. If you’re not familiar, please have a read. In this example, I utilize his Duplicate Your Data approach as a starting point. For a more recent alternative, you can also try this post from Joseph Everett at InterWorks.

Too Familiar

Here are the familiar, out-of-the-box reference lines from Tableau. Nice, but nothing fancy.

Coloring the Tips

Like most eleganance in Tableau, coloring the tips involves being creative. Each bar with a colored tip is in fact two bars, stacked.

The first has a length of, at most, the reference line. And the second bar (the colored tip) makes up the remaining difference, if there is any.

To get there we’ll need two calculated fields, and then stack the bars using Measure Values. Measure Names drives the color.

Two Calculated Fields

Keeping with comparisons of a sample to the population, I’ll structure the remainder of our example along those lines. The chart has one bar for each observed level of a factor variable within the sample, and a reference line for the population average.

And instead of a single bar for each factor level, we stack two bars by placing their break point at the reference line.

Display %

The length of the first bar will be, at most, no greater than the value of the reference line.

Display Diff

For those whose value extends beyond the reference line, we’ll stack an extra "Display Diff" bar on top. This is the tip in a different color.

Build the Vis

Now we have our building blocks, let’s assemble the vis. Eight structural considerations are described below.

  1. Measure Values is placed the Columns Shelf: filtered down to include only our two calculated fields

  2. Your factor variable of interest is placed on the Rows Shelf: one row per factor level

    • in the SFPD example: Incident Category
  3. Measure Names on the color shelf: and sequence is important here

    • Display % comes first, and Display Diff at the end
  4. Choose your colors

    • a muted grey for the base value works nicely
    • something bright & shiny (for pre-attentive cognition) works well on the tips, like a bright orange, red or blue
  5. Hide the Nulls Indicator

    • Nulls will appear in the Display Diff calc for bars that don't reach the reference line. And that's OK!
  6. If you haven’t added it already, then don’t forget the reference line

  7. Name the Axis: be clear, concise, and appropriate

    • Since more than one measure is on the columns, Tableau doesn't know how best to name the X Axis and by default calls it 'Value'.
  8. While you're here at the X Axis, if you haven't already: sort descending to get your bars in order.

Nice to Have

From here, a really nice addition to these bars is to place a value label inside of the bar itself. For this, I rather like Jonathan Drummey's dual axis 0.0 approach. I often find that labeling every single bar can be over-kill. So I prefer to label only maximum with a crisp, clean value inside of the bar.

Also, vis-a-vis Tim Costello, don't forget to comment your calculations!

Let me know your thoughts

Please take a look at the example workbook, and any further improvements to my technique are always welcome!

Word Count: 793

References

  1. "A Data Visualization Opportunity", Keith Helfrich, Red Headed Step Data, May 4, 2014: http://redheadedstepdata.io/quantcast-data-visualization-opportunity/
  2. "SFPD Incidents", Keith Helfrich, Red Headed Step Data, May 10, 2014: http://redheadedstepdata.io/sfpd-incidents
  3. "SFPD Incidents - Previous Three Months", San Francisco Data, Updated Daily: https://data.sfgov.org/Public-Safety/SFPD-Incidents-Previous-Three-Months/tmnf-yvry#Export
  4. "color-the-tips", Workbook, Tableau Public, May 16, 2014: http://public.tableausoftware.com/download/workbooks/color-the-tips?format=html
  5. "SFPDIncidents: data & analysis derived from the SFPD Crime Incident Reporting system", Repository, GitHub, May 16, 2014: https://github.com/keithhelfrich/SFPDIncidents
  6. "Maintain Percent of Total in Tableau Whilst Using Filters", Robin Kennedy, The Information Lab, January 14, 2013: http://www.theinformationlab.co.uk/2013/01/14/maintaining-percent-of-total-whilst-filtering
  7. "3 Ways to Preserve 'Percent of Total' within Filtered Dimensions", Joseph Everett, InterWorks, May 12, 2014: http://www.interworks.com/blogs/jeverett/2014/05/12/3-ways-preserve-percent-total-within-filtered-dimensions
  8. "Maintain Percent of Total in Tableau Whilst Using Filters", Robin Kennedy, The Information Lab, January 14, 2013: http://www.theinformationlab.co.uk/2013/01/14/maintaining-percent-of-total-whilst-filtering
  9. "0.0 Approach", Jonathan Drummey, Workbook, Tableau Public, http://public.tableausoftware.com/shared/JZXZBXGDT?:display_count=no
  10. "Comment Your Code in Tableau!", Tim Costello, InterWorks, May 13, 2014: https://www.interworks.com/blogs/tcostello/2014/05/13/comment-your-code-tableau
  11. "color-the-tips", Workbook, Tableau Public, May 16, 2014:

    Published by on