O'Reilly logo

ggplot2 Essentials by Donato Teutonico

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required