Create a bar chart with the individual data points

Priyanka Dobhal
4 min readJul 4, 2022

I’m pretty sure I don’t say this often, I love bar charts. They are the most powerful way to convey the message. But what we miss with a bar chart is that individual data point that is contributing to the chart. How do we focus on that?

That’s the question I had when I was building my visualization on “Diversity in Art: UK Gender Pay Gap”. My first draft was a simple yet powerful bar chart to see the pay gap between the Average annual salary of female and male.

This chart does convey the message, but how do I pin point the occupations in each bar? So that’s how I got to this final chart.

So let’s get to down to the steps. For convenience, I’ll demonstrate the steps using sample superstore dataset.

Initial Requirement

So what we are aiming to build is a bar chart showing Sales by Sub-Category and show the customer as points on the bar chart

Get the points

We need to distribute the points at most the max sales of each Sub-Category. For which, we will make use of the hidden and very power function in Tableau called Random()

It’s strange that Tableau doesn’t have mentioned this in their function list.

In simple word, RANDOM() returns a decimal number from [0–1]. This function does not take any arguments/parameters.

Create a calculated field: Random Rows
(random() * {FIXED [Sub-Category]: SUM([Sales])})

Now we also need to distribute the points randomly along column as well. Wondering why? Well, let’s see what we get if we just use random for rows

The points overlap and it’s hard to distinguish.

So let’s distribute randomly on column as well.

Create a calculated field: Random Columns
random()

Voila! first step done.

Bar Height

Now onto the bar chart showing the sales. This is where we get to use reference bands.

So first up, we need to get the sales by sub-category.

Create a calculated field: Sales by Sub Category
{FIXED [Sub-Category]: SUM([Sales])}

let’s add a reference band on random rows axis

So the band ranges from -100 to Sales by Sub-Category (Fixed calculation that we created). The lower limit is flexible and I decided on the basis of the points being shown up clearly.

The second part is the reference line on Random Rows to add label for Sum of Sales.

Adding Space between Bar

Now just to make sure the points are visible, I fixed the random columns axis at -0.1 to 1.1

Let’s add two reference lines for white space — two constant lines on -0.1 and 1.1

Phew! a lot of reference lines and bands, right? Don’t worry! We are done.

I would like to emphasize that this is definitely not the only way to do it. When I was working on the viz, I actually stumbled upon Jessica Moon’s #SportsVizSunday #Data21 Challenge. I reached out to her and she happily explained me how she implemented this trick using map layers and polygon, which is so cool! So I would definitely encourage you to check Jessica’s viz as well.

That brings us to the end of this blog post. Here’s the link to this sample workbook for your reference.

I hope you learnt something new today.

Stay safe and happy :)

Priyanka Dobhal

Twitter | LinkedIn | Tableau Public

--

--