Tips and Tricks
Data viz tips for parameterized reporting: set consistent axis limits
August 1, 2024
One of the biggest challenges we face when doing parameterized is how to make plots consistent across multiple reports. We’ve learned (oftentimes the hard way) many tricks for dealing with this problem. One I want to share with you today is making your axis limits consistent when making multiple plots. Here’s an example of a plot that shows median income by county for the annual Oregon by the Numbers . Let me show you a simplified version of the function I created to make these plots. We’ll...
How to make polished population pyramids in ggplot: part 2
July 18, 2024
I wrote recently about how I revamped the process of making population pyramids for Oregon by the Numbers , the report I’ve worked on for the last several years. Rather than making one plot, I used the patchwork package to stitch together three parts: A plot for women on the left Age labels in the center A plot for men on the right The result is a polished version of a population pyramid that I’m quite pleased with. The blog post I wrote about making this version of the population pyramid saw...
Animated versions of common dplyr functions
July 17, 2024
One of the best parts about the functions in the dplyr package (one of several that make up the tidyverse collection of packages) is that their names indicate what they do. No need to remember a weird acronym; the name of the function to filter your data is filter() . But, helpful as these function names are, it can still be hard to remember exactly what the functions do. In remaking my Fundamentals of R course in 2023, I had Albert Rapp generate animated versions of the most common...
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...