Workout Wednesday: Too Many Pie Charts?

This was originally posted on my first blog, Data vs Food, in December 2018


I quite enjoyed blogging about my approach to last week’s Workout Wednesday, so I thought I’d have another Go. Here’s the challenge for this week.

Luke’s original viz

My recreation

Taken in for Questioning

As I said last week, before I even open Tableau I have a play with the viz on Tableau Public and see what it does and I ask myself some questions: 

What do the tooltips show? 

The tooltips don’t show on the legend or on the state labels. The pie chart tooltips seem straightforward: state, sub-category,sales, % of sales in that state.

What sort of interactivity is there? 

The only interactivity is a parameter that allows selection of a subcategory. This updates all the pie charts and does some colour changing based on category.

What sort of marks are on show? 

Lots of pie charts (one for each state) that are each split into three slices: the selected sub-category, the other sub-categories within the same category as the selection, all other sub-categories. This split sounds the hardest part of the challenge.

The state name is also shown as a text mark.

Do I think there’s a dual axis involved? 

Yep. One for the pie charts, another for the state name.

What does clicking do? 

Legend – nothing

Labels – nothing

Pie chart – nothing

Click on bits of the dashboard and drag your mouse across, where do the sheets finish? 

Interesting. I assumed this was made up of two sheets, one for the legend and one for pie charts. However each row of states is a separate sheet, I wonder if I can save myself some work and only do this using 2 sheets?


It’s Tableau Time

Let’s make a grid of pie charts (I admit, I didn’t like writing that).

I’ll be using two discrete table calculations computed using the state name to generate a grid/small multiple/trellis chart (pick whichever name you prefer).

X: INT((INDEX()-1)%INT(SQRT(SIZE())))

Y: INT((INDEX()-1)/INT(SQRT(SIZE())))

These two calculated fields are placed on columns and rows respectively with state on detail.

Looks ok, not exactly pie charts though.

I created a parameter from Sub-Category and created the following calculation which is placed on colour



Selection:

IF[Sub-Category Parameter] = [Sub-Category]

THEN [Sub-Category]

ELSE[Category] END



I’ll be making changes to this calculation later, it doesn’t do quite what I want at the moment.

I also put [Sales] onto angle and added a Percent of Total table calculation computed using the above Selection.

That’s not looking too bad, time to sort out the Selection calculation. It needs to do 3 things:

  • Show the selected Sub-Category – Done

  • Show the remaining Sub-Categories that are in the same category as the selected Sub-Category – To Do

  • Show the other Sub-Categories – To Do

This took a fair bit of trial and error. Getting my head around the logic of this took some thinking.

In the end I used four calculated fields below:

(They’re displayed in the following way)

Field Name –What it does

What it is



Selection – Returns the selected Sub-Category or returns the field Selected Category

IF [Sub-Category Parameter] =[Sub-Category]

THEN [Sub-Category] ELSE [Selected Category]

END

Selected Category– This returns the Category of each Sub-Category with the same Category as the parameter. Otherwise it returns “Others”.

IF {fixed [Category]:sum(IF[Sub-Category Parameter] = [Sub-Category] THEN 0 END)} = 0 THEN [Category]

ELSE "Others"

END

Selection Colour – As Selection returns the name of the selected Sub-Category, this returns a copy of the Category to make the colouring a bit easier.

CASE [Selection]

WHEN "Others" THEN "Others"

WHEN [Category] THEN [Category]

WHEN [Sub-Category] then [Category (copy)]

END

Selection Sort – I needed consistent sorting, alphabetical wouldn’t work.

CASE [Selection]

WHEN "Others" THEN 3

WHEN [Category] THEN 2

ELSE 1

END

I feel like I’ve done a bit of duplication here, but while completing the challenge it was just kind of how my mind went through the problem. If this was something I’d have to maintain, there would be far more comments, simplification, and clean up required.


Chart Labels

One thing that’s drummed into the heads of anyone who starts out with Tableau is

“Don’t forget to synchronize your axis!”

And rightly so.

 

That’s exactly the rule I ignored to get the labels in the right place.

First I needed a dual continuous axis.

Leaving one marks card set to pie charts, I changed the other to text and removed every pill from it apart from State, which I put onto text. I then changed the start and end point of the axis scale until the labels were sitting nicely above the pie charts.

Afterthoughts

I’m writing this post a few hours after I published my viz and I found it quite difficult to explain how the four calculations actually functioned.

Forcing myself to review my work has helped me understand what my calculations do. Being able to put that in to words is the really hard part, I didn’t manage it as well as I’d have liked. Being clear and concise is so important here and is something for me to work on.

Also the word Category has lost all meaning

(it’s here 35 times in this post)

(not that I counted)