Skip to content
R for the Rest of Us Logo

Tips and Tricks

Advanced tricks to put your data into the right format with pivot_longer() and pivot_wider()

November 15, 2023

Last week, we started to learn about pivot_longer() and pivot_wider() . These are two essential functions to speed up you data wrangling process. Check out the video and blog post from last week if you haven’t seen that yet. As promised, this week we’ll continue on this path and learn some of the advanced tricks that these two functions have to offer. This should help you clean your data even faster. Let’s begin by revisiting what we did last week. Taylor Swift again Last week, we worked with...

Put your data into the right format with pivot_longer() and pivot_wider()

November 8, 2023

Conventional wisdom tells us that data wrangling is 90% of all data work. And it’s true. Often, you will have to get your data into the right format before you can get any “real” work done. In the tidyverse, there are two powerful functions to help you with one of the most common data wrangling tasks: going from wide to long and lnog to wide. These functions are pivot_longer() and pivot_wider() . Here, we will cover the standard use case of pivot_*() (we’ll cover more of what they can do next...

Five Steps to Improve Your Chart Quickly

November 1, 2023

Data visualization can be hard. From our experience, it can take hours and hours to perfect a visualization. Thankfully, if you’re stressed for time there are a couple of changes that always work. So let’s check out these evergreen steps we can use to make your chart instantly better. A chart to play with First off, let us create a dummy dataviz with our favorite penguins data set. Once we have that, we can apply little tweaks to make the overall look of our chart better. Use an active title...

Spice up your {gt} table with {ggplot}

October 25, 2023

Have you ever created a table with gt and thought to yourself “Well, maybe just showing the numbers doesn’t cut it? I need to add some visual spice to this table.” If so, then you’re in great company. Because spicing up tables with visuals is one of my favorite tricks. I like to add visual elements like small lines or bars to tables. Apart from making your table pretty, visuals help to convey an overall impression of the data to your reader. So, let me show you how you can add any chart to...

How to Order Bars and Lines in ggplot

October 18, 2023

With visualizations, it’s always better if there is some visual order in your charts. For example, take a look at these two bar charts. Which one do you find easier to read? And which chart gives you a better overview over the data? If you are like most people, then chances are that you will find that the sorted bar chart is easier to read. This simple action of sorting the bars can give a lot of structure to your data visualization. In turn, your chart is easier to understand for your...

How to add annotations in ggplot: should you use geoms or annotations?

October 11, 2023

Annotations are a neat way to draw your readers attention to specific parts of your data visualization. For example, you could use, say, an arrow to point to a specific data point, a rectangle to draw a border around specific points in a scatter plot that you want to highlight or a text label to clarify something. The possibilities for annotations are endless. Here’s a plot that combines these ideas into a ggplot. You can create such annotations with the annotate() layer. Who would have...

How to Create Your Own Table Theme with the gt Package

August 9, 2023

In our consulting work at R for the Rest of Us, we create tables all the time. We don’t just make plain tables, we make tables that look good and communicate well. This is important because: A clean design is more convincing A powerful design stands out so that people actually look at our tables We can use colors to reflect our clients’ branding We recently helped the Oregon Voices project to create customized data reports for every county in Oregon. Among other things, this required creating...

How to Use GitHub Actions with R to Run Code Automatically

May 26, 2023

In my course, Using Git and GitHub with R , I talk about GitHub Actions as one of the best reasons to use GitHub. GitHub Actions is a way for you to run code automatically, without you having to touch your computer. Maybe you run a survey and you want to pull the data every day. Or perhaps you want to generate a weekly report. Instead of manually running code in RStudio, you can use GitHub Actions to run this code automatically. Below, I will demonstrate two GitHub Actions: one that imports...

How to make your own color palettes in ggplot

January 23, 2023

One of the great things about creating data viz with ggplot is that you can create color palettes that match your or your clients' branding. We've written about how we do this in our consulting work . But the way we work is fairly complicated and I was asked recently for a simpler solution to making custom ggplot color palettes. I recorded a video to show how to make three different types of palettes Qualitative (i.e. categorical) Sequential (going from a low to a high value) Diverging (going...