Data Visualization – Part 3

What Type of Data Visualization Do You Choose (if any)?

Determining whether or not you need a visualization is step one. While it seems silly, this is probably something everyone (including myself) should be doing more often. A lot of times, it seems like a great way to showcase the amount of work you have been doing, but winds up being completely ineffective and could potentially harm what you’re doing. Once you determine that you actually need to visualize your data, you should have a rough idea of the options to look at. This post will explain and demonstrate some of the common types of charts and plots.

plot of chunk unnamed-chunk-2

This is Part 3 in a series about Data visualization:

Determine whether or not you actually need a visualizatoin in the first place.

Like the best practices I listed in Data Visualization – Part 1, make sure your visualizations:

  • Are clearly illustrating a relevant point
  • Are tailored to the appropriate audience
  • Are tailored to the presentation medium
  • Are memorable to those who care about the material
  • Are increasing the understanding of the subject matter

If these don’t seem possible, you probably don’t need a data visualization.

If you do need one, what’s a good first step to take?

Take a look at the forum in which you’re presenting, it matters! If you are writing for a scientific journal, it will be different than presenting live to a thousand person audience. Think about a Ted Talk compared to the Journal of Physics.

Point being: consider your audience!

Let’s talk about a high-level presentation. Everyone has seen a slideshow with fancy charts that add zero value. Do not be the person presenting something that way! Providing useless content will confuse the audience and/or lead to boredom.

If your point is to show year-over-year change of a single metric – show it as a simple number on the page in big bold font rather than a chart.

In this made up example, I am displaying revenue over the last few years (note: be more specific when it comes to what type of revenue you’re talking about).

Which of the following makes more sense to put on a slide?

plot of chunk unnamed-chunk-3

If you agree with me, the one on the right will be much easier for people to understand in a presentation. It gets the point across without requiring processing which will allow people to focus on what is important. Any additional nuggets you would like to point out can be spoken to.

Now, let’s talk about publishing content that isn’t for academic use but will reach the public (i.e. newspapers, magazines, blogs, etc.). These types of charts can cover a wide range of topics so we’ll have to stick to the basics. We’re going to look at displaying information which is interesting and adds value.

Here is a great example from Junk Charts in which the author of the original Daily Kos Article is showing a type of “lie detector” chart. The chart does a number of things well: it illustrates a relevant point, it is appropriate to the audience and medium, and really helps to understand the subject matter better. However, the original chart is too colorful which takes away from its effectiveness. Junk Charts took it to the next level by simplifying the colors and axes.

Original Version (Daily Kos)

plot of chunk unnamed-chunk-4

Modified Version (Junk Charts)

plot of chunk unnamed-chunk-5

By merely looking at this chart you can see how it is ranked, a sense of scale, the comparison between people, and clearly labeled names. Fantastic work!

Rather than going over more examples of work others are doing, please visit Chart Porn (don’t worry about the name, it’s a great data visualization site) and Junk Charts. They have phenomenal examples of what to do (and what not to do) when publishing to the public.

You have a point, now what?

There is no rulebook as to how to display your data. However, as you have seen, there are both great and poor options. The choice is up to you – so think long and hard before making a decision (and you can always try a number of them out on people before publishing).

Ask yourself the following questions to help drive your decision:

  • Are you making a comparison?
  • Are you finding a relationship?
  • Are you showing a distribution?
  • Are you finding a trend over time?
  • Are you showing composition?

Once you know which question you are asking, it will keep your mind focused on the outcome and will quickly narrow down your charting options.

Rule of Thumb

  • Trend: Column, Line
  • Comparison: Area, Bar, Bullet, Column, Line, Scatter
  • Relationship: Line, Scatter
  • Distribution: Bar, Boxplot, Column
  • Composition: Donut, Pie, Stacked Bar, Stacked Column

Obviously, there are plenty of choices beyond these, so don’t hesitate to use what works best. I will go over some of these basics and show some comparisons of poor charting techniques vs. slightly better ones.

For this project, I’ll use some oil production data that I found while digging through (pretty great site). The data can be found here

Let’s load up some libraries and get started.

Trend – Line Chart

Objective: Visualize a trend in oil production in the US from 1981 – 2016 by year. I want to illustrate the changes over the time period. This is a very high-level view and only shows us a decline followed by a ramp up at the end of the period.

Poor Version

The x-axis is a disaster and the y-axis isn’t formatted well. While it gets the point across, it’s still worthless.

plot of chunk unnamed-chunk-7

Better Version

The title gives us a much better understanding of what we’re looking at. The chart is slightly wider and the axes are formatted to be legible.

plot of chunk unnamed-chunk-8

Comparison – Line Chart

Objective: Identify which states affected the trend the most. Evaluate them simultaneously in order to paint the picture and compare their trends over the time period. From this visual you can see the top states are Alaska, California, Louisiana, Oklahoma, Texas and Wyoming. Texas seems to break the mold quite drastically and drove the spike which occurred after 2010.

Poor Version

There are far too many colors going on here. Everything at the bottom of the chart is relatively useless and takes our focus away from the big players.

plot of chunk unnamed-chunk-9

Better Version

This focuses attention on the top producing states. It compares them to each other and shows the trend per state as well. Using facet_wrap() tends to be used in what’s known as “small multiples” – this is a technique which helps to break up the visual components of the data into easy-to-understand pieces which make intuitive sense.

plot of chunk unnamed-chunk-10

Relationship – Scatter Plot

Objective: Check to see if data from Alaska and California is correlated. While this isn’t extremely interesting, it does allow us to use this same data set (sorry). The charts indicate that there appears to be a strong positive correlation between the two states.

Poor Version

Lots of completely irrelevant data! The size of the point should have nothing to do with the year.

plot of chunk unnamed-chunk-11

Better Version

The points are all the same size and a trend line helps to visualize the relationship. While it can sometimes be misleading, it makes sense with our current data.

plot of chunk unnamed-chunk-12

Distribution – Boxplot

Objective: Examine the range of production by state (per year) to give us an idea of the variance. While the sums and means are nice, it’s quite important to have an idea of distributions. While it was semi-apparent in the line charts, the variance of Texas is huge compared to the others!

Poor Version

Alphabetical order doesn’t add any value, names are overlapping on top of each other. While you can tell who the big players are, this visual does not add the value it should.

plot of chunk unnamed-chunk-13

Better Version

This gives a nice ranking to the plot while still showing their distributions. We could take this a step further and separate out the big players from the small players (I’ll leave that up to you).

plot of chunk unnamed-chunk-14

Composition – Stacked Bar

Objective: Check out the composition of total production by state. It’s interesting to see how the composition was relatively similar across decades until the 2010’s. Texas was 50% of the output!

Poor Version

My favorite, the beautiful pie chart! There’s nothing better than this… (no need for further commentary).

plot of chunk unnamed-chunk-15

Better Version

The 1980’s and 2010’s will be missing years in terms of a “decade” due to the data provided (and it’s only 2017). While the percentage labels are slightly off center, it’s certainly much better than the pie chart. It’s not quite “apples-to-apples” for a comparison because I created different decades, but you get the idea.

I also created an “Other” category in order to simplify the output. When you are doing comparisons, it’s typically a good idea to find a way to reduce the number of variables in the output while not removing data by dropping it completely – do this carefully and transparently!

plot of chunk unnamed-chunk-16

Some other fun concepts are below!

Some of them are nice, others are terrible! I won’t comment on any of them, but I felt it was necessary to include some other ideas I toyed around with.

Have fun with your data visualizations: be creative, think outside the box, use tools other than computers if it makes sense, fail often but learn quickly. I’m sure I’ll think of a thousand better ways to have illustrated the concepts in this post by tomorrow, so I’ll make updates as I think of them!

Now it’s your turn!

As always, the code used in this post is on my GitHub

plot of chunk unnamed-chunk-17

plot of chunk unnamed-chunk-18

plot of chunk unnamed-chunk-19

plot of chunk unnamed-chunk-20