Skip to content
R for the Rest of Us Logo

Tips and Tricks

How to make polished population pyramids in ggplot: part 1

July 11, 2024

How do you make a population pyramid in ggplot2 ? These charts, which allow us to see the distribution of the population by gender and age, are common ways to examine demographics in a particular place. The ggplot code needed to make a population pyramid is quite straightforward, but, as you’ll see in this blog post, you can go way beyond straightforward to make a polished population pyramid (try saying that three times fast!). I’ve made hundreds of population pyramids for the last few years...

A step-by-step guide to parameterized reporting in R using Quarto

June 27, 2024

Parameterized reporting is one of the best reasons to use R. This technique allows you to generate dozens, hundreds, even thousands of reports at the same time. In this blog post, I give you a walkthrough of how to use parameterized reporting with Quarto. You'll learn what parameterized reporting is, how parameterized reporting works, how to add parameters to your Quarto documents, and how to use an R script file to render multiple reports. You can watch the full video below or follow the...

Parameterising a multi-part plot

June 19, 2024

Today’s #rstats exercise in building parameterised plots is brought to you by my desire to avoid copy-pasting and making minor edits to 200+ lines of code in order to create two variants of a set of interactive graphs for a client. I decided to blog my way through the process to highlight a few tips and tricks I’ve picked up along the way. The visualisation I’m working on comprises 5 graphs, all interactive (and connected to each other in their interactivity), and all created straight from...

How to create maps of the US with ggplot

June 6, 2024

Ever wanted to create a map of the US with ggplot? We know that we have. For example, for our Oregon Voices project , it was invaluable to have a great package that allows to create nice charts of the US. In this blog post, we show you how to get started with creating maps in R. And with that said, let’s dive in. Our first map chart We start with a simple map of the US. The cool thing is that we don’t have to do much work to make that happen. All of the heavy lifting is done for us by the...

How to remove unwanted texts in your data

May 23, 2024

Text cleaning is a common part of data analysis. You may not really want to do it but it’s often necessary. For example, have a look at this data set from tidyTuesday. It shows you the stock prices of some big tech companies. Maybe you want to work only with this financial data set. But at some point you will probably have to communicate your findings to someone else. And if these people are anything like me, then they probably don’t immediately know which company is meant by a symbol like...

Use shadowtext to add outlines to your texts

May 8, 2024

As probably most of you know, the premier package to create charts in the tidyverse is ggplot2 . On its own, this package is already incredibly powerful. It really cannot be stressed enough that you can create impressive charts with just this one package. Still, there are some things that ggplot cannot do on its own. And one such thing is adding outline strokes to texts like this: See that black outline around the text? That’s the work of an extra package called shadowtext . On it’s own...

Use snippets in RStudio to repeat common patterns

April 24, 2024

Sometimes it’s the little things that can give you a productivity speed boost. That’s why we’ve already looked into great RStudio keyboard shortcuts that can make your programming life easier. In today’s blog post, we want to highlight another one of RStudio’s excellent features, namely reusuable code snippets. For example, check out this function: Here, I’ve created a simple function that adds two vectors. There are two ways to create this: Write this all out (including all of the special...

How to separate a single column into multiple ones

April 10, 2024

Every now and then it happens that a lot of information is crunched into one column. For example, take a look at this data about board games from tidyTuesday . Notice how the column of boardgamecategory contains a lot of labels. These labels represent all of the different categories a board game can fall into. Now, if we wanted to visualize the most popular board game categories, we might make a chart like this: But the question becomes: How do we count the board game categories if all of...

Let the {styler} package help you reformat your code

March 27, 2024

The tidyverse style guide offers many helpful suggestions for how to write your code. Of course, the style guide is very opinionated as all style guides usually are. Still, in our R courses we try to adhere to the tidyverse style guide as much as possible because we believe that this makes for pretty legible code. Now, even as seasoned tidyverse users, we sometimes mess up our code structure. This is just a normal thing that happenes to everyone. So to save some time trying to fix the...