3MW (6 dataviz principles any ggplot course should teach)

Guten Tag!

Many greetings from Ulm, Germany.

Let us talk about dataviz principles that every ggplot course should teach. I'm talking about principles that are so easy to implement that you could even do it in a beginner’s course.

And remember: All of today’s free code can be found on GitHub.

Make sure your labels are legible

We start with a really simple one. The principle is simple: "Use proper axis labels and increase the font size”. For example, take a look at this plot.

The texts are waaay to small and the axis labels do not mean a thing. Let’s fix that. In ggplot, this can be done in just two lines:

  • Change labels with labs() 

  • Increase the font size by using base_size in theme_gray()

That's it. It's not hard to implement this but it will be so much better for your reader who actually has to read your plot. See for yourself:

Use a minimal theme

As a rule of thumb, you should minimize everything that could potentially distract your audience. That’s why I usually recommend to use a minimal theme: Just use theme_minimal() instead of theme_gray().

Format labels

Now that you can read the labels, you may have deduced that the data shows lengths of cells related to tooth growth. Also, we can see multiple dosages of “OJ” and “VC” that seem to affect the tooth growth cells. But what the hell is “OJ” and “VC”?

If you know the data, then it’s clear that the supplements were orange juice and a vitamin C supplement. But your reader will not necessarily know that. Thus, the labels should make clear what’s what.

Implementing that has nothing to do with ggplot. Just transform the labels before the data is even passed to ggplot().

Put categorical labels on the y-axis

In the previous plot, the categorical labels could be written on the x-axis. But with many categories this is not always possible. Check out this plot.

The labels overlap. And instead of trying to tilt the labels, just map the categories to the y-axis instead. In ggplot(), you can just change x and y in the aes() call. Literally no additional code needed.

Take a look how we can fit all the labels onto the image now.

This concludes this week’s 3MW. I hope you enjoyed this week’s issue and I wish you a great week! 🙃 

In the subscribers-only part, we learn a simple trick to avoid more clutter and a simple way to include these methods into your workflow.

Subscribe to 5 Minutes Wednesdays to read the rest.

Become a paying subscriber of 5 Minutes Wednesdays to get access to this post and other subscriber-only content.

Already a paying subscriber? Sign In

A subscription gets you:
Extra long weekly Newsletter
Reading time: 5 instead of 3 minutes
Access to all premium content
Discounted early access to new courses

Reply

or to participate.