Tips and Tricks

How to make heatmaps in ggplot
May 1, 2025
Heatmaps are a common way of representing data. In this blog post, I'll show you how to make your own heatmaps using ggplot. In the process, you'll learn a bit about working with the {sf} package, specifically the st_make_grid() function to make a grid, the st_intersection() function to clip the boundaries of your geography to the grid you create, and st_join() to do spatial joins. This blog post is adapted from a lesson in the Mapping with R course . If you want to learn to make heatmaps...

Use shadows in ggplot to highlight findings
April 24, 2025
In our consulting work, we make a lot of the data visualization for parameterized reporting . It’s something I spoke about in my 2024 Cascadia R Conf talk, How to Make a Thousand Plots Look Good: Data Viz Tips for Parameterized Reporting . One example I gave in this talk came from our work with the Johns Hopkins International Vaccine Access Center and the World Health Organization . In this project, we made reports for the Immunization Agenda 2030 project, which tracks the progress countries...

Create your own custom {ggplot2} theme
April 3, 2025
Creating custom themes in {ggplot2} lets you elevate your data visualizations from standard to standout. Whether you’re aiming for a polished, brand-consistent look for your organization or a unique aesthetic that reflects your personal style, a custom theme function makes it easy to apply your design to all figures with a single line of code. In this tutorial, we’ll cover: the essentials of the powerful ggplot2::theme() function, including how to adjust fonts, colors, sizing, and spacing;...

Hide text labels with small values to make charts made in ggplot easier to read
March 13, 2025
One issue that we often face when making data visualization in reports is text not fitting into graphs. This happened to us when working on reports for the Connecticut Data Collaborative and the Partnership for Strong Communities in Connecticut. The reports we made , which show key demographic and housing indicators for towns and counties across the state, have bar charts that show the housing cost burden for renters and home owners in the state. In addition to the categories severe burden...

From Overwhelm to Organization: Optimizing Data Workflows in R
February 20, 2025
Ever feel overwhelmed by a messy R script that's grown out of control? That's exactly what happened to Alberto Espinoza , Knowledge and Learning Manager at PEAK Grantmaking . In his job at PEAK Grantmaking, an organization that helps philanthropy to use equitable, effective grantmaking practices, Alberto supervises a Grants Management 101 class . As part of this training, Alberto has to analyze data from surveys that participants complete. With this training happening regularly, the data from...

Report Design in R: Small Tweaks that Make a Big Difference
January 30, 2025
In August 2024, I spoke at posit::conf about doing report design in R . As I say in the talk, I never thought I'd become known for making nicely designed PDFs , but it's one thing we at R for the Rest of Us have become known for in the R world. The talk, titled Report Design in R: Small Tweaks that Make a Big Difference, was a great chance for me to share some of the things we've learned about making good reports, focusing on consistency, avoiding defaults, and incorporating brand elements...

R Versus Python: Which One Should You Learn?
January 16, 2025
If there is one question I get asked more than any other, it's this: should I learn R or Python? Especially in recent years, many people have developed a vague sense that Python is replacing R (the rebranding of Posit from RStudio in order to serve multiple languages scared many longtime R users). But I think the discussion of whether R is declining is misguided. Because ultimately the question of R's decline is less relevant to the question of which language you should learn. More relevant...

Automate file management in R with the {fs} package
January 9, 2025
Imagine you’re working on a project, and you receive a folder filled with subfolders and files named in different styles: some in uppercase, some in lowercase, and with a mixture of spaces, dashes, and underscores. This disorganized chaos can make it hard to find anything, but the {fs} lets you quickly rename and organize everything to a consistent case and format. This guide will show you how to use {fs} to automate tedious tasks like creating, renaming, moving, and deleting files and...

Use geom_ribbon() to highlight the gap between two lines
December 19, 2024
I recently found this really nice graph in the New York Times and I thought it was really effective, particularly the fact that it shows two lines and only shows the spread over a specific period. So how can we replicate this in R, particularly the shading of the gap between existing mortgages and rates on new loans? In this guide, written with Joseph Barbier, I’ll walk you through the steps of creating a line chart with two lines, where the area between the lines is filled only for a...