## Show Me How: Unit Charts

In this post we’ll talk through building Unit Charts (also know as Pictogram Charts) – i.e. charts using icons to represent a quantity – in Tableau. It will be an advanced topic using Table Calculations.

#### Show Me How: Intermission

I thought it might be worth a quick break from our Show Me How Series for a “commercial break”. Our Show Me How series is all about bringing the Show Me Bar to new users, but what happens when the chart type you want isn’t available? Perhaps you’ve graduated from Show Me and you’re wondering how to apply some more advanced techniques to build the chart types you want. Well that’s what we’re advertising in this commercial break.

What goes in Show Me are generally visualisation types that can be created via a simple rearrangement of the pills on rows, columns, and marks; that means that often people ask for visualisations that just aren’t in the standard list. One such example is Unit Charts, click the image below to read about these charts in the Data Visualisation Catalogue:

#### Best Practice

Unit Charts are certainly not best practice from a visualisation standpoint, I’ve rarely seen a visualisation where a bar chart isn’t a better option. However they look cool, so we should establish a few do’s and don’t around using them so that we can remain good Tableau citizens:

DO use Unit Charts to tell you’re audience what you’re counting (e.g. people) when it might be unclear.

DO include a legend and ideally a label.

DO stick to understandable units 1, 10, 100, 1000, 10000, etc.

DON’T use varied numbers of symbols to build each stack – it can leave the user confused.

DON’T use partial symbols – again it may leave the user confused.

#### Building in Tableau

If you’re stepping away from the safe harbour of Show Me and the regular chart types then please be aware that there are some choppy waters ahead of us. We’ll be using several Table Calculations in the building of this visualisation and if you aren’t comfortable with them then I suggest you sail over to my blog post Understanding Tableau Calculations using SIZE() and INDEX() for a primer. I’ll try and explain each step of the build as we go along to help you, and I’ve included an explanatory Viz. Here’s what we’re going to create.

[tableau url=”https://public.tableau.com/views/ExampleUnitChart/UnitChartDashboard” width=”675px” height=”750px”][/tableau]

Step 1: Set up the Parameters

Unit Charts usually have several elements, the number of rows of pictograms that make up each “bar” (three in the example above) and also the number of items referred each pictogram (100 in the example above).

Let’s set up these parameters in Tableau:

[Grid]: Integer: Default Value = 3

[Person Size]: Integer: Default Value = 10

Step 2: Set up the Initial Calculated Fields

[ColumnID] = int(((index()-1)/[Person Size])/[Grid])+1
[RowID] = ((index()-1/[Person Size]) %  ([Grid]))+1

These two similar calculations are the basis for the chart, ColumnID breaks each element we’re counting (each Order in this case) into a set of columns, and RowID does the same for rows.

When we add Continent to Rows and OrderID to Detail, then add ColumnID to Columns and RowID to Rows (important – they need to be Discrete pills for now) – and set each to compute over OrderID – then we build a grid of orders.

The first Order goes into Column 1, Row 1; the second into Column 1, Row 2; the third into Column 1, Row 3, the fourth goes back into Column 1, Row 1, and this continues until each Row / Column has [Grid] elements in it, then the Column Number increments and the “buckets” fill up again. I’ve added a visualisation below which shows this, with the Orders numbered to help understand what these calculations are doing.

[tableau url=”https://public.tableau.com/views/CreatingaTableauUnitChart/RowsandColumns” width=”800px” height=”600px”][/tableau]

Step 3: Set up the Initial Calculated Fields

Now create a calculated field, drag it to Filters and Compute over OrderID:

[Person Filter] = (index()-1) % [Person Size] = 0

This has the effect of “hiding” all the orders except the first in each “bucket”, so only the 1st, 11th, 21st Orders are shown. See below:

[tableau url=”https://public.tableau.com/views/CreatingaTableauUnitChart/Hideallexceptfirstineachblock” width=”800px” height=”600px”][/tableau]

Step 4: Change the Mark Type

Change the Mark Type to Shape and click on the Shape button to choose an appropriate Shape. Change the width of the Rows and play with the Size (again just click on the Size button) – I find it works best spot in middle of the slider for shapes.

[tableau url=”https://public.tableau.com/views/CreatingaTableauUnitChart/ChangetoPeople” width=”800px” height=”600px”][/tableau]

Step 5: Change the ColumnID to Continuous

…and hide the headers for RowID and ColumnID. Remove the Gridlines and other formatting to tidy up the Viz.

Changing the ColumnID to Continuous fits everything on the page and let’s you play with the Person Size parameter to see what works well – try changing it to 100 in the Viz below.

Also build a label:

[Sum Label] = if [RowID] = 1 then str(window_sum(countd([Order ID]))) + ‘ <crlf> orders’ end

This labels the first row only. Add it to labels and adjust the alignment of the label to show to the right of each symbol, it will only show on the last one of the row as it overlaps the others…ensure it also computes over OrderID.

Feel free to download the above explanation Viz to help understand the methodology. The rest of this example can be found in the final viz.

Step 6: Add another Category to Colour if needed

Now if you want to add another Category to Colour then go ahead but you’ll need to change your Compute Using context for each of your Table calcs using the Advanced section of the Edit Table Calc:

The order of the Addressing fields matters, this is because it is this ordering that decides how the underlying data is ordered. If you put your colour Dimension first (like I have Customer Segment) then it will order by that first, meaning all your colours will be grouped together.

Remember to set this for all your Table Calcs – they all have a triangle symbol, as well as RowID and ColumnID don’t forget the filter, and don’t forget the nested Table calc on Label – you’ll need to use the drop down in the Edit Table Calc window to alter both the outer [Sum Label] calc, and the RowID it uses.

Step 7: Finish it off

I used a separate worksheet to add a legend and added the floating parameter underneath. I tidied up the formatting. I grouped the calculations into their own folder. All this is nice to do bu tno essential.

[tableau url=”https://public.tableau.com/views/ExampleUnitChart/UnitChartDashboard” width=”675px” height=”750px”][/tableau]

#### Alternatives

This method is only really applicable when you have the lowest level of detail in your data, in this case orders. What happens when you don’t? Well Steve Carter used a great technique in his Adoption Gap visualisation to blend in a grid of data points representing each shape – download his workbook and see what you think.

Nottingham, UK

### 9 thoughts on “Show Me How: Unit Charts”

Superb thanks Chris, a very clear step by step guide.

Used sparingly and in the right way, a fantastic info graphic

cheers

2. Neil Brosnahan says:

Hi Chris,

Is there any way to use this Size / Index for auto-sizing text just like you are doing for shapes? I was wondering if you knew a way to apply this same method to eliminate the “…” when the text can’t fit in a cell.

Sincerely,
Neil

1. Chris Love says:

Hi Neil – good question….not really I’m afraid though it’s something I’ll think about and see if I have a solution…

3. Jessica Walker says:

Is it possible to replicate this dashboard based on Sales instead of Order ID? I am basically wanting to create a view that would be similar to a “Sales by Continent” (with the Customer Segment color addition) dashboard using the workbook you created above. I can’t seem to figure out how to do it.

4. Stefanie Ledbetter says:

Chris,

I am new to Tableau (like 3 weeks new with no sql training) – I have been able to replicate most everything above but I am only getting one person shape per row. Instead of my person representing 100, I need each person to represent 1 patient. I used the Grid = 3 and Person Size = 1 but I am not sure what to do next. Everything else works.