Skip to content
Coming soon: Ally. Your guide to the world of AI and R. Learn More →
R for the Rest of Us Logo

Tips and Tricks

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...

How to know if your data is tidy

March 13, 2024

One of the most frequent questions we get when we teach R is “How do I know if my data is in a tidy format?” Rightfully so. Tidy data is a powerful concept and I remember asking myself the exact same questions when I first learned about tidy data. So to help you answer this question, let me give you an answer to this question that eventually helped me and made my life easier. But beware: You might find the answer a little bit unintuitive at first.Forget about tidy data Yup, that’s right....

Use tidyselect helpers to grab the right data

February 28, 2024

Tidyselect helpers are neat little helper function that help you, well, select the right data. This can make your life easier when you want to either grab many different columns or even transform many columns using across() . For example, have you ever found yourself typing out repetitive calculations like this: Here, we converted all the measurements that are given in millimeters (mm) to centimeters (cm). To do so, we had to divide the mm numbers by 10 (yay, metric system 🥳) and select all...

How to add sparklines to a {gt} table

February 14, 2024

Any table can be spiced up by adding small visual elements to it. Ideally, this makes the table more engaging and informative. One popular visual element that can get both jobs done is a sparkline . These are little line charts in a table cell that can give you a miniature overview of a time series evolution over time. Sounds complicated? It probably becomes clear when you see it in action. Here, have a look: See those little lines. They show you exactly how the open price of the stock prices...

How to work with times and dates

January 31, 2024

Time series data is everywhere. But time- and date-related data is notoriously hard to work with. But as always, the tidyverse has a nice package that makes our life just a little bit easier. In this case, it is the lubridate package that helps us. But just like time data itself, it requires a bit of effort to get used to working with lubridate . In this blog post, we go through a couple of things you might struggle with when you want to work with time data. This should help you get started...