16 ggplot

ggplot is based on a grammar graphics - a way of approaching describing the construction of a graphic from common building blocks. Building a graphic with ggplot then follows some common patterns of construction.

At its most basic, we supply ggplot with a dataset and some aesthetics–that is, the variables we wish to display on the plot and how they should appear. Laslty, we define a plot type.

Step by step this looks like

  1. call ggplot()
  2. provide ggplot with a data set
  3. provide ggplot with the variables of interest and their aesthetic properties
  4. define a plot type with geom_plotType()

This is a brief introduction. For more in depth examples and solutions, check out ggplot2: Elegant Graphics for Data Analysis by Hadley Wickham, Danielle Navarro, and Thomas Lin Pedersen.