Monday, September 22, 2014

Think Outside the Box!

I am long overdue for both a viz and a post to Viz For a Cause, so I decided to kill two birds with one stone. In August, my wife and I spent two weeks in Haiti working at an orphanage, so adoption has been at the top of my mind lately. The final viz is just below. Keep scrolling if you want details on how I built the radial menu.



TC14 actually had a pretty huge impact on this viz, specifically the “Designing Vizzes That Stop Traffic” session by (in order of appearance) Dan Montgomery’s legs (@DanRMonty), Paul Banoub (@paulbanoub), and Anya A’Hearn (@datablick). If you aren’t following these guys yet, you should really evaluate some of your life decisions. Definitely catch a replay of the session if you can get access to it. A few of the themes throughout the session were keep it simple, viz what’s important to you, cup stacking, explore other layouts besides a grid and steal like an artist (the idea for the household grid came from Dan's "Show Me the Money" viz). 

I was really intrigued by the idea of a viz that wasn’t built on a grid. Maybe it was a random idea, or maybe it was Paul's donut viz, but I really wanted to find a way to do a radial menu in Tableau. I wanted to stay away from pie charts, so a scatter-plot and a quick geometry refresher from our good friend google were my only options. For those of you that want to repeat this, here’s what you need to know.

Note: Before you begin, you'll need to decide how many points you want on your radial menu, or at least provide a parameter to let users pick.

To determine the (X,Y) coordinates of a certain number of points on a circle with a radius of one, centered on 0,0, the first step is to figure out the number of radians between each point. For those of you unfamiliar with radians (example: me), it is essentially a fancy way to measure an angle. A circle is composed of 360 degrees or 2π radians. Knowing this, you can graph a circle using the following formula, nπ/(z/2) where n is the current point being graphed (ex. The first point will be 1, the second point will be 2 and so on) and z is the total number of points, in our example it will be 40. To put this in to practice, on a 40 point circle the first point would be  determined by an angle of π/20 radians. The 37th point would be determined by an angle of 37π/20 radians.

Now that you know how to determine the angle for each point you can determine the (X,Y) coordinates using the following formulas:
X – SIN(radians)
Y – COS(radians)

Here’s how these formulas looked in Tableau (in italics below). Though you won’t see it in the final viz, I originally used a parameter to allow the user to select anywhere between 20-40 countries. This allows the circle to dynamically re-plot points if you want to vary the number of items on the menu. I really liked this feature, but in the end decided it wasn't really adding anything to the viz (as Dan would say "Keep it Simple Stupid!")

Points (z/2 from our formulas above) - [Countries to Display Parameter]/2

Note in the below that RANK_UNIQUE was used because some countries had the same number of adoptions, and you’ll need to have all numbers between 1 and 40, no room for a tie! This field just identifies which point in the circle is being graphed.

Rank (n from our formulas above) - RANK_UNIQUE(SUM([Adoptions]))

The X and Y formulas will look something like this:

X - COS([Rank]*PI()/[Points])
Y - SIN([Rank]*PI()/[Points])

These are table calcs, and after adding them to your viz, you should be computing along your dimension of choice, in my example they use country.

That's it! Place X in the columns shelf and Y in the rows shelf and your dimension (whatever is determining your points) on shape and color and remove all headers and gridlines. If you've done everything right, you should have something that looks like the screenshot below:



Another point of interest here that didn’t play a factor in the final viz but is a cool trick was my "Size" measure. This comes in handy if you are going to be changing the number of points in your circle. The formulas is, 10/[# of  Countries Parameter]. You can see in the screenshot (bottom left, Size menu) that as the user switched from 10 to 20 to 30 to 40 the value of this size measure would change from 1 to .5 to .75 to .25, allowing for larger shapes with fewer points and smaller shapes with more points.

Finally, there is the household grid. This was a HUGE thorn in my side. This was another semi-complicated math solution so I am going to cover that one in a second blog post. However, I do want to give a shout out to Dan Montgomery who came up with a really killer way to make an X by X square that would plot points dynamically based on a variable number of shapes. It was also set up in such a way that the shapes would resize to fill the entire viewing area. This solution didn’t make the final viz, but inspired the 10x10 house grid you see in the final viz. Dan is going to be doing a full write-up on the solution that he came up with so head over to his blog and check out his past posts while you wait for that!

A few other people to thank for this viz, most of all my talented and beautiful wife who provided the title logo, country shapes and the "LEARN MORE" icon. It was a much different looking dashboard before her files were added! Also special thanks to everybody at Slalom that provided input and feedback!

Family and Child icons designed by Jens Tärning from the Noun Project