Tidy Tuesday is a weekly event where the a set of data is provided to the community via github, and anyone and everyone is encouraged to make a visualization from the data. It's not a competition, or paid work. I was browsing #tidytuesday on Twitter and saw this chart by Dan Ohem (you can find Dan's github here. He makes a lot of cool charts and I highly recommend checking it out):

globalHumanDayOGTweet.PNG

I had pictured making something like this myself, but didn't have any experience making something this complicated in R. This visualization was so sleek and pretty, I decided to dive into Dan's code and learn how he did it.

And well, it was almost the visualization I was thinking of making myself - rather than compare global and Australia (Dan's home nation), I was more interested in comparing countries I assumed would have the largest difference among them - the countries with the highest Human Development Index (HDI) and those with the lowest.

This project isn't really a project-project. The data was provided, the code for the visualization was provided. However, by doing this I was learning some spiffy R code and methodology, and I was practicing a skill a lot of people don't really think about too often - the ability to read other people's code. And not just read it, in this case, but understand it well enough to make changes and add my own stuff to it without breaking everything. It seems like it'd be trivial, but I promise you that it can be an entirely new beast to wrestle with.

There are a lot of benefits and uses for being able to read others' code, starting with the entire reason I decided to do this project - exposure. If you are only ever interacting with code you know already how to write, then you're never exposing yourself to the next level and seeing what you could be capable of doing. It's an excellent way of leveling up your own coding skills. Next, especially in work or collaborative settings, you might often need to debug or review someone else's code. And lastly, if you ever integrate a section of code you didn't write yourself into your own code, then you need to understand how it works and how to integrate it. Being able to trace a function from its inputs to its outputs is vital.

So naturally, the first step was reading through the code and commenting everything. You can compare Dan's code to mine below:

GlobalHumanDay_2.PNG
GlobalHumanDay_1.PNG

And naturally, when I copied over his code from github, it didn't work because helper functions were missing. Before I found where they were hiding in his directories, I tried my hand at replicating the to_hm function based on what I thought it was doing and what the output looked like. Theoretically, it was converting the time durations for each category provided from something like '1.07 hours' to '1h 4m'. My almost-there function looked pretty close to Dan's and I'm happy with that.

GlobalHumanDay_3.PNG

Deciphering breathing_space_on_x was entirely different, though. It had four inputs and from the name of the function, I could guess it was related to placement and separation of the labels, but without the actual function I was at a complete loss. But once I found it, I started changing values and seeing what changed in the chart to figure out what the input variables corresponded to. I'm not gonna lie, this was probably the most tedious part of this project, but I felt like a top-tier Holmesian investigator when I finally figured out the last piece of the puzzle.

GlobalHumanDay_4.PNG

From there, I had to subset the data for the Top 20 and Bottom 20 HDI countries, whose names I collected from UN Human Development Programme. I had to change the code to accommodate for the fact that the second chart now had to wrangle the data from 20 countries rather than just one (Australia). So I got to practice and reinforce some data manipulation techniques as well. The last step was figuring out placement of everything, including the values to impart to breathing_space_on_x. I thought about changing the color palette, but in the end I liked Dan's best and opted to keep it.

GlobalHumanDay_5.PNG

In the end, I had the visualization I wanted, I learned how to make a cool chart type in R, and I practiced some valuable code-related skills. Short and sweet! Check out the finished product below.

global-human-day.png