Tips and Tricks
How to Read R Help Pages
October 10, 2022
Folks just starting out with R often assume that those of us who are more experienced never need to get help. This is definitely not true! Everyone always searches for help, no matter how advanced an R user you are. Learning how to search for help when you need it is a key skill. One of the places user typically look for help is in the help files that are loaded when you type ?function() (replacing function() with an actual function name, of course). These help files have a particular format...
Automating Sentences with R
October 3, 2022
The thing that first drew me to R was the ability to run the same analysis on different datasets and get a similar output every time: the same graphs, the same analyses, the same structure to the report, but different data, so a different story to tell. We often talk about the power of R in making research analyses reproducible, or in generating parameterized reports which all include variants of the same graphs, but one thing we haven't talked much about is the role R can play in automating...
How to Make a Donut Chart in ggplot
September 9, 2022
A lot of data visualizations are designed to show multiple data points (think bar charts that compare results for multiple groups). But what if you want to show just one data point? Say, for example, you want to show what percentage of people have accomplished something? There are two techniques we often use in our consulting work to show single data points: Donut charts: These are pie charts with a hole in the middle (hence, donuts). Pie charts with multiple slices are problematic (people...
Aligning Your Axes
July 17, 2022
At R For The Rest of Us, we spend a lot of time creating bespoke parameterised reports for our clients. In these reports, we often use CSS to create polished documents and to control the placement of our images. We've written about this approach elsewhere. In a recent project creating a needs assessment report on farmworkers in Oregon, we needed a bit of extra problem solving to make sure that the X axes of two plots, placed side by side, were aligned horizontally. This is the main thing...
How to merge data and calculate multilevel summaries
June 17, 2022
In one of the lessons in Fundamentals of R, I teach people how to use the group_by() and summarize() functions to calculate simple summaries (e.g. if I have population data on all states, what is the total population of the United States?). But what if you want to group by a group that's not in the original data frame? We got a question on this recently: Let's say I had state level data with numerical values per state. Let's say I wanted to assign each state to relevant regions, like...
How to tidy select all that apply questions in R
May 17, 2022
Surveys often have multiple choice, select all that apply questions. Being able to wrangle this type of data in R can be challenging. Figuring out the right way to get your data into the (tidy) structure necessary for visualizing it with ggplot can be complicated. And, to make things even more complicated, different survey tools spit out data from select all that apply questions in different formats. This blogpost is going to demonstrate how we would use tidy data principles and the tidyverse...
How to get started with the bookdown package
April 18, 2022
Ever since I started working on my book R Without Statistics people have asked me for details on how I'm writing it. If your mental model for how a book gets written involves dozens of Word documents, you may be in for a surprise (my father certainly was). In writing R Without Statistics, I'm using the bookdown package. The bookdown package allows you to create a series of RMarkdown files, bundle them together, and create an online book like I've done with R Without Statistics. I recently...
Announcing R Without Statistics
April 4, 2022
n early 2020, I started to have conversations with publishers about doing a book on R. I was excited about the possibility, but wasn't exactly sure what the book would be about. Then COVID came and, with two young kids at home, writing a book was not going to happen. In the two years since then, I had a lot of time to think about what type of R book I am uniquely placed to write. By last fall, I had a decent idea: a book that highlights all of the ways you can use R that don't involve complex...
Why R is Magic
March 8, 2022
A couple weeks ago, I had the opportunity to speak to some folks at Western Michigan University. I called my talk Why R is Magic. Because, well, it is. I busted out my favorite R party trick: doing a survey and immediately generating a report with RMarkdown. I even tried something new by sending out the reports to people by email using the gmailr package. (Yes, you can send email from R. Did you now know that it’s magic?) The folks at the Western Michigan Evaluation Center were kind enough to...