Session Ready
Exercise

Many variables

In addition to aesthetics, facets are another way of encoding factor (i.e. categorical) variables. They can be used to reduce the complexity of plots with many variables.

Our goal is the plot in the viewer, which contains 7 variables.

Two variables are mapped onto the color aesthetic, using hue and lightness. To achieve this we combined fcyl and fam into a single interaction variable, fcyl_fam. This will allow us to take advantage of Color Brewer's Paired color palette.

Instructions 1/3
undefined XP
  • 1
    • Map fcyl_fam onto the a color aesthetic.
    • Add a scale_color_brewer() layer and set "Paired" as the palette.
    • 2
      • Map disp, the displacement volume from each cylinder, onto the size aesthetic.
    • 3

      Add a facet_grid() layer, faceting the plot according to gear on rows and vs on columns.