Sorting colours in stacked by charts by value

Stacked bar charts can be very useful, but they often have one rather large downside: if you have two similar sized segments within the same bar, how can you tell which is larger?

Let’s take a look at the following stacked bar chart:

non-sorted-colours

Here we are looking at the percent of total purchase value, of the top 5 foods sold between 1990-2000; as you can see, the colours are in the same order for each bar. I have also included the labels for each segment in each bar to demonstrate that they are not sorted by their value (even though this is already pretty obvious).

After you’ve built your original view, here are the steps to sort the colours by their value:

  1. In the Dimensions pane, hold down the CTRL button, and select the field which appears in your rows and the field which is shown by colour – in this case we select both the Year field, and the Food Type field.
  2. Click on the drop down arrow on one of the highlighted fields, and select Create Combined Field. 
  3. In the Marks card, right click on your colour field (in this case Food Type), and select Attribute.
  4. Drag the combined field made in step 2 to Detail in the Marks card.
  5. Right click on the combined field in the Marks card, and select Sort
    1. Under Sort order, select Descending;
    2. Under Sort by, select Field;
    3. Under Field, select the same field and aggregation that appears in your rows – in this case we choose Purchase Value and Sum;
    4. Click Okay.

These steps achieve our desired result:

sorted-colours

As we can see from the labels of each segment, they are stacked in order of descending value.

Here is a video showing the above steps in action:

[youtube https://www.youtube.com/watch?v=mPHJkv0pP0Q&w=560&h=315]

 

If you want to see how I built the whole worksheet (including the sorting), check out this video:

[youtube https://www.youtube.com/watch?v=YMVAi-hYFeQ&w=560&h=315]

Try it for yourself!

 

Author:
Bethany Fox
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab