Introduction to ggplot2

Content for Wednesday, November 9, 2022

R provides a number of different packages for generating plots of your data, but ggplot2 is probably the most common owing to its ability to use consistent syntax to produce a variety of different graphics. In addition to plots of data and model objects, ggplot2 can also be used with sf objects and some raster datasets to generate publication quality maps. In addition, many of the map-specific plotting packages follow syntactic principles that mirror ggplot2 so learning it provides a foundation for some of the spatial visualizations we’ll work on later.

Resources

Objectives

By the end of today, you should be able to:

  • Understand the relationship between the Grammar of Graphics and ggplot syntax

  • Describe the various options for customizing ggplots and their syntactic conventions

  • Generate complicated plot layouts without additional pre-processing

Slides

The slides for today’s lesson are available online as an HTML file. Use the buttons below to open the slides either as an interactive website or as a static PDF (for printing or storing for later). You can also click in the slides below and navigate through them with your left and right arrow keys.

View all slides in new window Download PDF of all slides

References

Healy, K. 2018. Data visualization: A practical introduction. Princeton University Press.