The goal of this course is to train students to create publication-quality graphics in R.
The course will emphasize the relationships between data structure and graphical elements so students can apply what they learn to other R package extensions not covered in the course. A mix of lectures and in-class exercises provide a thorough overview of two primary graphics packages in R: base and ggplot2.
In addition to plot customization basics (e.g., color, symbology), students will learn more advanced data visualization techniques (e.g., multiple axes, insets, transformations). The final day of the course is dedicated to guided practice; students may work with their own data or choose from our set of example projects.
- Customize code from base and ggplot2 packages
- Apply the “Grammar of Graphics” system underlying ggplot2
- Manage data structure with dplyr and tidyr to facilitate graphing
- Write functions to automate data preparation and generate graphics
- Transform default graphics into beautiful, customized, publication-quality graphics
Previous completion of an Introduction to R course and/or some experience using R is required.
Students must bring their own laptops with current versions of R (v3.4.3) and R Studio (v1.1.423) installed. We also recommend students pre-install the following packages: ggplot2, tidyr, dplyr, lubridate, scales, forcats, and sf.
Monday, November 5th, 2018. R Review and Introduction to Graphing in R.
- Quick review of R and R Studio.
- High-level overview of graphing in R.
- Principles of good graphic design.
- Descriptions of main graphic packages in R.
- Data structure and graph design.
Tuesday, November 6th, 2018. Base graphics.
- Modifying base graphics.
- Data style (color, shape, line type, etc.).
- Text (add/remove text elements, change text font).
- Structure (layer plots, arrange multiple plots on page).
Wednesday, November 7th, 2018. Basic ggplot2 graphics.
- Introduction to elements of a plot per the “Grammar of Graphics”
- Aesthetic mapping, geometries, coordinates
- Groups and facets
- Scales and guides
- Data structure and data management tips
- Using dplyr and tidyr to prepare data for ggplot2
- Organizing structure of ggplot2 functions
Thursday, November 8th, 2018. Advanced ggplot2 tasks.
- Common advanced features of publication-quality graphics.
- Applying user-defined statistics.
- Incorporating multiple axes (e.g., time series of temperature and precipitation).
- Managing complex legends and other text annotations.
- Fine tuning thematic elements.
- Helpful tips to automate and standardize plot construction.
- Extensions and add-on packages for base and ggplot2.
Friday, November 9th, 2018. Guided practice.
- The last day of this course will emphasize hands-on practice coding publication-quality graphics. Instructors will provide datasets and associated exercises designed to give students more practice at building base and ggplot2 graphics. Exercises will include examples from a range of biological and environmental fields. Alternatively, students may choose to work with their own data to practice designing and building graphs specific to their research projects.