ABSTRACT

This chapter illustrates how the ggplot2 package can be used to create data graphics. Other packages for creating static, two-dimensional data graphics in R include base graphics and the lattice system. The chapter employs the ggplot2 system because it provides a unifying framework—a grammar—for describing and specifying graphics. The grammar for specifying graphics l allows the creation of custom data graphics that support visual display in a purposeful way. The ggplot2 package is one of the many creations of prolific R programmer Hadley Wick-ham. It has become one of the most widely-used R packages, in no small part because of the way it builds data graphics incrementally from small pieces of code. In the grammar of ggplot2, an aesthetic is an explicit mapping between a variable and the visual cues that represent its values. The aesthetic is the mapping that defines these correspondences. When more than two variables are present, additional aesthetics can marshal additional visual cues.