Introduction

This set of computer labs was written in R Markdown (Allaire et al. 2024) and created from assignments used in the course Data Analysis & Visualization in R at The Evergreen State College. If you’ve found your way here, then you are probably an Evergreen student (or know one), probably in the Master of Environmental Studies (MES) program, and want to get more practice using R. Each lab has a Citations section and links to background information.

If you’re an instructor/faculty and interested in using or adapting this for your own course(s) - feel free! As you’ll see, I’ve used a lot of different resources, and adapted material from many of those books or sites to create the exercises.

Some advice for getting started

When the lab refers to a .csv file, those can be found on the Statistics Resources page of the MES Thesis site.

If you’re new to R, and/or just have never felt that comfortable using RStudio, then use some of resources below - or find your own - before jumping in to the labs.

Before starting, you should be able to:

  • Download and/or update R and RStudio
  • Import data (e.g. from a .csv file)
  • Install and load packages
  • Create a new project (.Rproj) and save commands and notes to a script (.R)

One good resource is this McGill University Library site which has many specific pages that can help you get started:

Also helpful are these chapters from (Dauber 2024):

AND this chapter from (Wickham et al. 2023), which is especially important if you’re not used to working in R projects:

Finally, as you’ll see in Lab 1, I’m going to recommend the Wickham et al. approach to keeping the Source of Truth in your R scripts…

The Labs

Lab 1: Workflow and Tidying is an introduction to the tidyverse collection of packages (Wickham 2023)

Lab 2: More tidying & ggplot continues with some additional tidying functions, and begins to use ggplot2 (Wickham et al. 2024), which is used for (nearly) all plotting and visualizations in the rest of the labs.

Lab 3: Logistic Regression using glm() introduces the glm() function, first with an example of simple linear regression but then with an extended example of logistic regression.

About the Author

John Withey is a member of the faculty in the Master of Environmental Studies (MES) program at The Evergreen State College in Olympia, WA. You can learn more about John on his faculty and weebly pages. John had this to say about these labs:

I started my scientific career as a field biologist studying birds. I learned R as a graduate student because I needed to use a ‘resource utilization function’ to analyze my field data on crows and there was a package available for it. Being able to use an open source program AFTER you’re a student is invaluable. You can find a package for nearly any analysis you read about in the literature, and the options for plotting and mapping are endless. Rather than ‘make’ you an expert in a particular area, my goal in my teaching, and for this collection of labs, is to help you learn to find good options for data analysis and visualization in R.

Acknowledgements

I’ve had the privilege to teach with some remarkable teaching partners in the MES core program Research Design and Quantitative Methods, including Carri LeRoy, Shawn Hazboun, John Kirkpatrick and Kathleen Saul. My work in that course, and developing the dataR course as a follow up, was influenced by all of them.

My time to put together these materials and publish them was supported by The Evergreen State College Foundation through a Sponsored Research Grant.

Citations

Allaire, J., Y. Xie, C. Dervieux, J. McPherson, J. Luraschi, K. Ushey, A. Atkins, H. Wickham, J. Cheng, W. Chang, and R. Iannone. 2024. Rmarkdown: Dynamic documents for r.
Dauber, D. 2024. R for non-programmers: A guide for social scientists.
Wickham, H. 2023. Tidyverse: Easily install and load the tidyverse.
Wickham, H., M. Çetinkaya-Rundel, and G. Grolemund. 2023. R for data science. 2nd edition. O’Reilly Media, Inc.
Wickham, H., W. Chang, L. Henry, T. L. Pedersen, K. Takahashi, C. Wilke, K. Woo, H. Yutani, D. Dunnington, and T. van den Brand. 2024. ggplot2: Create elegant data visualisations using the grammar of graphics.