4 Quadrant Square Chart, another method

Hello everybody, I bet you had a great time at TC19! For those of us who stayed at home we had a great time watching the sessions online, I don’t need to be in Vegas! (I do!).

Some time ago 4 quadrant square charts were the thing in our Tableau community, do you remember? There are lots of really cool visualizations that have used them and there are several blog posts that have covered how to create them: Kevin Flerlage and his No Polygons (and polygons) technique, Rosario Gauna using LODs and some clever calculations, Rody Zakovich using just the SQRT() function and adjusting the size of the bar charts and Rajeev Pandey using a pack of calculations.

Well, I have found yet another method to create them! The credit for this technique goes to Toan Hoang and his incredible course in Udemy, Creating Bespoke Visualizations in Tableau, this course provides you a framework that allows you to experiment and create new vizzes, be sure to check it out!

This new technique is based on the fact (?) that a square is a special type of curve that can be drawn using parametric equations, but what are these? Well, according to Wolfram Mathworld: Parametric equations are a set of equations that express a set of quantities as explicit functions of a number of independent variables, known as “parameters”. If you need a more friendly approach, like me, there’s an excellent post by Ken Flerlage that goes deeper on this subject, be sure to read it.

The whole foundation of this technique are the following formulas for X and Y:

x = a * (|cos θ| * cos θ + |sin θ| * sin θ)

y = a * (|cos θ| * cos θ – |sin θ| * sin θ)

where a is the length of the sides of our squares.

For this example I will use a pretty simple dataset consisting of my family members and their ages, you can copy-paste it to Tableau:

Name, Age
Adolfo,41
Erika,35
Estefi,8
Regis,5

First we will use data densification to have enough data points to draw our squares, you can use whatever technique you feel most comfortable with, I used unioning the dataset to itself using Tableau.

Tableau will create a new column named [Table Name], we will use it to create our path field:

[Path]
IF [Table Name]="Sheet1" THEN 1 ELSE 361 END

Then we will create a bin from this field, just right click on [Path]>Create>Bins… and set the bin size to 1.

Next, we will create our [Index] field that will work as the degrees for our sin()/cos() functions:

[Index]
INDEX()-1

Now we will create the calculations that will set the size of our squares depending on the value of each of the members of our dimension, in this case the names. To do this we need to use Table Calculations to access the age of each member and the max age available, in this case, mine. You can do it in just one calculation but I prefer to do it separately to avoid confusion:

[TC Age]
WINDOW_MAX(MAX([Age]))
[TC Max Age]
WINDOW_MAX(MAX([Age]))

Yes, those are equal but the addressing and partitioning will be different. Next, we will normalize the age of everyone according to the max, this will give us a number between 0 and 1, so our biggest square will have sides of length 1.

[Age Normalized]
[TC Age]/[TC Max Age]

We are going to create a ranking, this will help us later to determine the location and sorting of our squares.

[TC Rank]
RANK_UNIQUE([TC Age])

Now we are ready for our X and Y values, we will use the formulas mentioned at the beginning of this post:

[X]
(([Normalized Age]/2)*
((ABS(COS(RADIANS([Index])))*COS(RADIANS([Index])))+
(ABS(SIN(RADIANS([Index])))*SIN(RADIANS([Index])))))
+([Normalized Age]/2)
[Y]
([Normalized Age]/2)*
((ABS(COS(RADIANS([Index])))*COS(RADIANS([Index])))-
(ABS(SIN(RADIANS([Index])))*SIN(RADIANS([Index]))))
+([Normalized Age]/2)

The blue part on the calculations are just the parametric formulas to draw our square, the orange part gives the size to the square and the green part shifts the square so the origin is at 0. We can now create the first part of our chart:

1. Drop the [Path (bin)] pill into the Path card, be sure to set this field to “Show Missing Values”.

2. Drop X on Columns and Y in Rows.

3. Right click on both fields and set the table calculations as follows:

You should have something like the picture below, which can be considered as a pretty cool visualization by itself, Bloomberg Graphics uses them frequently in their reports and they look pretty neat:

Chart from Bloomberg’s https://www.bloomberg.com/news/articles/2019-11-12/election-2020-how-the-economy-will-shape-u-s-presidential-race

Now we have a pretty cool chart but that’s not what we want, we want our quadrants! To achieve that we need two more calculation and our previous calculated [TC Rank] field:

[X Quadrant]
IF [TC_Rank]=1 OR [TC_Rank]=4
THEN 1
ELSEIF [TC_Rank]=2 OR [TC_Rank]=3
THEN -1
END
[Y Quadrant]
IF [TC_Rank]=1 OR [TC_Rank]=2
THEN 1
ELSEIF [TC_Rank]=3 OR [TC_Rank]=4
THEN -1
END

What these calculations do is to position the squares according to the rank of each member, the member with the highest value would be on the top-right quadrant and the member with the lowest value would be in the bottom-right quadrant. We need to add these new calculations to our X and Y calculations:

[X]
[X Quadrant]*
(
(([Normalized Age]/2)*
((ABS(COS(RADIANS([Index])))*COS(RADIANS([Index])))+
(ABS(SIN(RADIANS([Index])))*SIN(RADIANS([Index])))))
+([Normalized Age]/2)
)
[Y]
[Y Quadrant]*
(
([Normalized Age]/2)*
((ABS(COS(RADIANS([Index])))*COS(RADIANS([Index])))-
(ABS(SIN(RADIANS([Index])))*SIN(RADIANS([Index]))))
+([Normalized Age]/2)
)

We need to set the addressing and partitioning of the new fields in both X and Y:

You should end up with something like this:

Wait a minute, that doesn’t look like squares! Fear not, we just need to adjust the axes, I suggest something like -1.1 and 1.1, now we have our 4 quadrant square chart!

You can use lines.

Or you can use polygons.

I haven’t tried but I’d assume that this is scalable to be used on small multiples. Also I haven’t done the calculations to show the labels and values, some tricky calc would be required on the polygons since they don’t have available the Text card.

I hope you find this technique useful. Please comment and share, that’s the only way I know you like my content.

Thanks!

Adolfo

Leave a Comment

Your email address will not be published. Required fields are marked *