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
The Data Visualization: A Practical Introduction by (Healy 2018) provides a lot of examples of Tufte-style graphics built with
ggplot2.Graphic design with ggplot2 is an entire course devoted to making beautiful visualizations with
ggplot2. If nothing else, check out some of the examples!The
patchworkpackage website provides a lot of examples of building complicated layouts withggplot2objects with intuitive syntax.
Objectives
By the end of today, you should be able to:
Understand the relationship between the Grammar of Graphics and
ggplotsyntaxDescribe the various options for customizing
ggplots and their syntactic conventionsGenerate 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