- 3 Minutes Wednesdays
- Posts
- 3MW (6 dataviz principles any ggplot course should teach)
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.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/4fb3a90e-45e0-488e-b18d-781644d7fda2/image.png)
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
intheme_gray()
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/01b4aac2-de68-4af3-a163-dc7c1838d7a4/carbon_155_.png)
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:
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/834f0b17-5b41-4959-9a50-bb79a381f9fd/image.png)
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()
.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/1706d79e-18d6-4398-8a83-09e2a67eb869/image.png)
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.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/fd55e9dd-2984-4382-a0ee-9a97e7baae3b/image.png)
Implementing that has nothing to do with ggplot
. Just transform the labels before the data is even passed to ggplot()
.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/3475d160-4dc6-4fb4-a4d2-ee8ab7a8fcd8/carbon_160_.png)
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.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/d8c1f628-33bb-48d5-b7bb-805b071e4a62/image.png)
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.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/83ab9080-2dff-458e-b88d-23eeb77b7f8d/carbon_161_.png)
Take a look how we can fit all the labels onto the image now.
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/95e53927-1511-4286-adf0-e02c17db3cf0/image.png)
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.
![](https://media.beehiiv.com/cdn-cgi/image/format=auto,onerror=redirect/uploads/publication/logo/dcd4eaf2-0a16-4f6e-a277-324841b39e98/thumb_Twitter_header_-_6.png)
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
Reply