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

13 comments:

  1. Two things - 1. I am amazed about the estimated amount of orphans in India - incredibly eye opening. Putting it in contrast to # of US households really puts it perspective. 2. The circle placement of countries and household matrix are tableau magic!

    ReplyDelete
  2. Wow! The content and presentation - wow!

    ReplyDelete
  3. Love the creative viz ideas and story. Nice work!

    ReplyDelete
  4. Beautiful viz, and a great purpose. I love this all around!

    ReplyDelete
  5. Great idea for layout. I might not have explored the dashboard if it had been more conventional but the novelty encouraged me to interact and discover the story in the data. Great stuff. Thanks also for the explanation on how you did it.

    ReplyDelete
  6. Excellent way to present a complicated subject (and thanks for the trip down math memory lane).

    ReplyDelete
  7. Thanks all for the comments, important topic to me and my wife, so all the positive comments mean a lot!

    ReplyDelete
  8. Awesome design. I can't view it at the moment, so I think you've gone beyond traffic stopping and created a Tableau Public-stopping viz!

    And thanks for describing the Tableau techniques. It's nice to see how you put it together without having to download and reverse engineer. I had a couple of questions on the design

    Is there an order to the countries? Normally, I think you'd have one, but maybe this works better unordered to get users to interact more?

    Was also curious if you decided to use % instead of ratios. For me, it's easier to grasp 6 out of every 1000 US households instead of 0.6%, but there are different theories on which is more effective.

    I wonder also if you've buried the lead --- the adoption rates differ significantly by country. Ghana had 40% more adoptions than India, but India had 40 times as many orphans as Ghana! Perhaps you could start with the traffic stopping viz you have now and use story points to show a couple more traditional views. Or, if you have the vertical real estate, skip the story points (gasp!) and let users scroll.

    Thanks again for sharing -- my comments are more out of curiosity than critique -- it's a cool viz. Congrats on Viz of the Day!

    Jim

    ReplyDelete
    Replies
    1. Hi Jim,

      Thanks for your kind words and feedback! Apologies for the delayed response...

      There actually is "somewhat" of an order, but it's not necessarily intuitive. I had to index on something so that each country had a 1-40 value, which is based on # of adoptions. If you start with China and then go counter-clockwise, you'll see the # of adoptions going down. Honestly, sorting outside of the required index didn't really cross my mind at the time, I was too busy brushing up on my trig! A better way might have been to start at the top and proceed clockwise in order, but the math would get significantly more complicated as you would be going from pi/2 radians to zero radians, and then 2*pi radians to 1*pi radians and then back to pi/2 radians. The way it is right now I can start with pi/20 radians and then just proceed counter-clockwise in order 2pi/20, 3pi/20, etc. using my index as the number that comes before pi in the (X * pi)/20 formula.

      I actually started out with a ratio and got feedback that it was confusing. In the original viz I had "1 in 2 households would have to adopt from China" and "1 in 1749 households would have to adopt from Guinea-Bissau". For China, I would only show 2 households with 1 highlighted and for Guinea-Bissau I showed 1749 households with one highlighted. I got the feedback that this was confusing, because 1 in 2 looked smaller with the fewer households, while the 1749 houses looked like a "bigger problem" at first glance. I decided, with some help, that percentage more clearly communicated the message.

      Thank you again, love the support of the Tableau community!

      Delete
  9. Steven, this is simply brilliant! Taking complexity and making it simple is no small task. It's wonderful to see what happens when you break free! Congrats to your wife as well - lovely collaboration.

    ReplyDelete
  10. This is a phenomenal visualization - elegant and insightful. Really well done.

    ReplyDelete
  11. Awesome vis, could you do a walk through of how you did the houses in the middle, that could be very beneficial to a lot of people

    ReplyDelete
    Replies
    1. I am LONG overdue for a post explaining the household grid. If you want to contact me directly (stevenc@slalom.com) I can send you what I have in draft form right now. Will hopefully get it posted here soon. Thanks for your kind words on the viz!

      Delete