Book Image

ggplot2 Essentials

By : Donato Teutonico
Book Image

ggplot2 Essentials

By: Donato Teutonico

Overview of this book

Table of Contents (14 chapters)
ggplot2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Layers in ggplot2


As just discussed in the previous section, we saw how important the concept of layers was when creating a plot with ggplot2. These layers are then combined with a coordinate system and other transformations which then generate the final plot. But what exactly are the layers? In the grammar of graphics as implemented in ggplot2, the layers are responsible for the objects that we see in the graph. Each layer can come from a different dataset, have different geometry, and have a different aesthetic mapping. As you can see in Figure 3.1, the layers are composed of several components—the data, aesthetic, geom, stat, and position adjustment. Not all these components are needed in order to create a layer, but a minimal layer can be created just by including the data, aesthetic mapping, and geom that will define the type of plot to be generated. In fact, the geometry is a very important component of the layer since no visualization is possible without specifying the geometry.

Data...