2 For beginners

Excerpt adapted from: Hadley Wickham, Danielle Navarro, and Thomas Lin Pedersen. ggplot2: Elegant Graphics for Data Analysis (3rd edition). Online version available at https://ggplot2-book.org. Source code: https://github.com/hadley/ggplot2-book. Copyright © Springer Nature and the authors. Used here for educational purposes under fair use.

ggplot2 is an R package for producing visualizations of data. ggplot2 uses a conceptual framework based on the grammar of graphics. More complete information about how to use ggplot2 can be found in the book.

For structure, we go over the 7 composable parts that come together as a set of instructions on how to draw a chart.

gplot2 needs at least the following three to produce a chart: data, a mapping, and a layer. The scales, facets, coordinates, and themes have sensible defaults that take away a lot of finicky work.

In this tutorial you’ll learn:

  • About the mpg dataset included with ggplot2

  • The three key components of every plot: data, aesthetics and geoms

  • How to add additional variables to a plot with aesthetics

  • How to display additional categorical variables in a plot using small multiples created by faceting

  • A variety of different geoms that you can use to create different types of plots

  • How to modify the axes

  • Save the Plot