## Friday, 15 April 2011

### Defending Pie Charts!

Anyone who knows me (in the BI world) knows that I have a certain lack of respect for the humble Pie chart.  I am supportive of Stephen Few's idea that we should, in general, Save the Pies for Desert.

A Pie chart, as it ubiquitously appears in many presentations, used to compare one value against several others, is a very poor choice for the task.  A simple bar chart is by far the better choice for the job.

I have been quite happy, up till now, to reject any use of a pie chart for any purpose.  That was until I came across Robert Kosara's blog entry, In Defence of Pie Charts.  Robert discusses Spence and Lewandowsky's study which shows that pie charts were interpreted more accurately than bar charts in some circumstances.

So, perhaps there is a good use for the Pie chart after all - not in comparison of multiple values, but in simple part-to-whole comparison.

Take, for example, the following Pie chart where we are comparing the performance of Germany versus all other countries.

Now, this chart doesn't give me any numbers but what it does give me is an intuitive feel for how much of the market Germany has.

Now, compare that to an equivalent bar chart.

Here we have a perfectly formed bar chart where we can get a good grasp of the numbers that are involved.  However, if I want to get an idea of what percentage the German total is versus the whole, I have to do a little more work to get the answer - I can't intuit it.

So, for this specific purpose, a Pie chart might be a better choice than the bar.

These charts are easily achieved in QlikView using implicit set analysis (available since version 9).

The chart has no dimension but has 2 expressions.  In my case, the expressions are:

Sum({<Country=P({\$})>} LineSalesAmount)

and

Sum({<Country=E({\$})>} LineSalesAmount)

When I select one or more countries, the first expression will give me the total for the selected countries.  The second expression gives me the reverse, the total for all the other values.

The labels for these can be achieved using Concat.  For the selected countries:

='Selected: ' & Concat(DISTINCT Country, ', ')

For the other countries:

='Others: ' & Concat({} DISTINCT Country, ', ')

Stephen Redmond is CTO of CapricornVentis a QlikView Elite Partner

1. Hi Stephen,

Thank you for this useful tip.
However, the expressions should be as follow:

For the selected countries:

Sum({\$} LineSalesAmount)

and for the other countries:

Sum({1-\$} LineSalesAmount)

2. This comment has been removed by a blog administrator.

3. Hi guys,

Could you tell me how can I create a Pie Chart selecting one value from one dimension and create an "Others" with all the others dimension's value?

Dimension: Customer
Expression: Sum(Sales)
Relative - Checked.

I want to see the % of sales for one selected customer versus the % of the others (all together).

Regards,
- Gabriel

4. Nice! You've demonstrated a good example of even a simple comparison in a pie chart, where pie might be better suited than bar;
Why could you intuit?
Pie makes angles significant. The vertical and the horizontal divide the pie into 25%. The line is almost (benath the) horizontal, hence this amount is a little more than 25%.