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

Legends

As we mentioned in Chapter 3, The Layers and Grammar of Graphics, legends are guides that represent the inverse of the applied scales and are used to trace back the plot elements to the aesthetic mapping. For this reason, legends are defined in ggplot2 as guides since they represent guides to the aesthetic mapping. The legend that is created by ggplot2 depends on the aesthetic mapping and the geometry that is used in the plot. For instance, Figure 5.1 contains a continuous color scale, Figure 5.2 contains boxplots, and Figure 5.4 contains points.

Since legends are recreated by scale functions, most of the time you will need to use scale functions to modify the legend's appearance. In this section, we will go through how to change the four ...

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