R tutorials

Pros and Cons of R
R How-to videos
My favorite packages
Other R resources

Code sample for using the Bureau of Labor Statistics API
Code sample for CDC vaccine data

Questions? Contact MaryJo Webster. If you like my work, please consider making a small donation via PayPal. Thank you!

Tutorials

How to use these tutorials:

Download R and RStudio (free desktop version). See the "Getting started with R and RStudio" video below to help get going.

Download data and script files to go with all the tutorials from my github repo

The remaining tutorials and videos are set up to gradually increase your knowledge, while also giving you a chance to practice the basics you learned in previous lessons. The numbered tutorials all have script files with them where most of the code is already written for you, plus spots where you will add some of your own code. Midway through are a series of DIY lessons that come with instructions but you will have to create a project, a script file and write all the code yourself. There is a separate file with the answers that you can check when you're done. (Don't cheat!)

For the Tidycensus class, you will need to get a Census API key from here.

Not all the tutorials have matching videos.

Use the how-to videos to troubleshoot specific things, like importing or using dplyr or joining tables.

1) Getting started with R and RStudio

This talks you through installing the software and some packages and gives you a brief tour of RStudio. The github repo includes a script file with code you can use to install all of the packages needed for all of these tutorials.

2) A gentle introduction to R

This walks you through starting your first analysis project, import some data and use a little bit of Tidyverse code to start looking at the data. See link above for downloading data to follow along.

3) Analysis with Tidyverse

This gets you a little further along Tidyverse code for data analysis, but is still very much a beginner lesson. See link above for downloading data and script to follow along.

4) Death data analysis with Tidyverse: This is a continuation of the previous exercise, but this time using more complex data from the Minnesota death certificates database. Brief introduction to making plots with ggplot2. Use the link at the top of the page to download the data and script from my github repo.

DIY/ Police Shootings exercise: Download the files from the github repo and follow the instructions. This is designed for you to practice launching a project, creating a script file and getting it all up and running on your own. Then refer to the answer file to check your work.

5) Cleaning data: This walks you through some basic cleanup, recoding and rearranging techniques such as pivot_wider and pivot_longer. Use the link at the top of the page to download the data and script from my github repo.

DIY/ Salaries exercise: Download the files from the github repo and follow the instructions. This is designed for you to practice launching a project, creating a script file and getting it all up and running on your own. Then refer to the answer file to check your work.

6) Importing, joining and appending data: This focuses on how to import csv and Excel files, as well as joining and appending data, but also offers additional practice in some data recoding, a basic plot and basic analysis. Use the link at the top of the page to download the data and script from my github repo.

DIY/ student diversity exercise: Download the files from the github repo and follow the instructions. This includes practice joining data and adding some new variables. This includes an answer file to check your work.

7) Intro to ggplot2- part 1

This video introduces you to the basic syntax for making bar and column charts with ggplot2 package from Tidyverse. Use the link at the top of the page to download the data and script from my github repo.

FYI: I made a few tweaks to the code that are not reflected in the videos. Nothing too major, though.

Intro to ggplot2 - part 2

This video shows you how to make line charts, grouped column charts, grouped line charts and stacked column charts using ggplot2.


8) Using Tidycensus

Tidycensus is a package created to make it easier to pull Census data from the U.S. Census Bureau API. This alone is worth learning R for because it's much easier to pull large chunks of Census data than using the data.census.gov interface.

This tutorial shows you how to use Tidycensus, from a basic data pull to more complicated ones that allow you to get multiple years or multiple geographies at the same time. The second video gives you a brief introduction to a couple different ways to make maps in R using the Census data.

To get started, download the data and code from my github repo. You'll end up with a folder called "8_tidycensus" and within that will be a script file. Open RStudio; create a new project and point it at the folder. Then open the script file from within RStudio.

FYI: the code has been updated to pull 2019 data (instead of 2018 and 2017 data, which is what you'll see in the videos)


9) Using RMarkdown

This tutorial shows you how to write your code in an RMarkdown file and then "knit" it into a pretty HTML page (with the option of hiding your code). This is a great way to make a beautiful presentation of your findings to share with others. It also shows you some other formatting tools such as the formattable package and the DT package for making a searchable, sortable table. Use the link at the top of the page to download the data and script from my github repo.

10) COVID exercise

This is a way to put many of your new skills to practice on a full data analysis. It also shows you how to download data from a live URL (in this case, the New York Times COVID cases and deaths data by county). Use the link at the top of the page to download the data and script from my github repo.

11) Building permits exercise

This series of 3 videos walks you through an analysis of building permit data. You'll get to practice importing, basic analysis, data cleaning and data visualization with ggplot. It also includes detailed instructions for using pivot_wider and pivot_longer.

Use the link at the top of the page to download the data and script from my github repo.

Part 1


Part 2


Part 3


12) Using Esquisse to learn ggplot

This R package, called Esquisse, launches a GUI interface to help you build charts using ggplot code. It writes the code for you and lets you insert the code into your script. It does have some limitations, but might be a good way to get started with ggplot.