R Office Hours

Emma Clarke, Isabelle Feldhaus, Louisa Smith

PHS 2000

Welcome to the official site of the R office hours materials.

Spring Semester

You can catch up on the fall semester topics using the links below!

February 13: Making summary tables code

February 20: Review and de-bugging practice Rmd file

February 27: Writing functions

March 13: Functions and test review

March 27: Loops

May 8: A new way to reshape data

Schedule

In the spring semester, all sessions will be held Wednesdays from 3:30 to 4:30.

Date Leader Room
February 13 Emma Kresge 204
February 20 Emma Kresge 204
February 27 Emma Kresge 204
March 6 CANCELLED -
March 13 Louisa Kresge 204
March 20 SPRING BREAK -
March 27 Louisa Kresge 200
April 3 Emma Kresge 200
April 10 Louisa Kresge 200
April 17 Emma Kresge 200
April 24 Louisa Kresge 200
May 1 Emma Kresge 200
May 8 Louisa Kresge 200

Fall Semester

(Right-click and download links to save data files)

September 5: Introduction to ggplot; data

September 12: Filtering data; data

September 19: Selecting columns with select()

September 25/26: Making new variables with mutate()

October 2/3: Using factors to work with categorical variables

October 9/10: Using summarise() and group_by() to summarise your dataset

October 16/17: Review and challenges

October 22/23: Improving data visualizations with facets and themes

October 30/31: Tidying data using gather()

November 6/7: Going back to wide format using spread()

November 20: Separating and uniting variables in your dataset

November 27/28: Merging datasets

December 4/5: Working with dates and times

December 11/12: Tips and tricks for de-bugging code

R resources

Used to SAS or STATA? These guides ( SAS and Stata ( 1 & 2)) can help you translate from those languages to R.

Some people love learning R with Swirl, which teaches you to code interactively.

Here’s RStudio’s great list of online resources. In particular, there are some more online tutorials here.

Hadley Wickham is probably the #1 R guru and has written several books about R, which you can read on his website, where you can also learn more about the packages he’s written, including ggplot2.

Here’s another book with a good introduction to data science R, including data visualization.

The fivethirtyeight package has a ton of cool datasets that you can play around with.

If you’re not understanding an error message, clear your workspace and/or restart RStudio and try again. Does the error still show up? Then try writing a minimal working example. What does it take to reproduce the error? Is the problem with your data, your code, or both?

Watch this video of an expert walk through her process of debugging code (even experts get error messages all the time!).

It may sound silly, but copying and pasting error messages into Google is usually the fastest way to solve a tricky problem. You will almost certainly end up on the relevant stack overflow question page, because someone somewhere has experienced the error you’ve encountered.

Struggling with ggplot? Take a look at this cheat sheet or this gallery. This website is another great resource.

Ready to make your plots beautiful? Choose your color scheme with the RColorBrewer package. Explore ColorBrewer palettes here. “Set1” and “Dark2” are favorites for qualitative data and “BuGn” is nice for sequential gradients.

This Rmarkdown cheat sheet is helpful for getting started.

Can’t remember the name of a certain Greek letter? Try detexify.