Exercise

Grouping variables

We'll continue with the previous exercise by considering the situation of looking at sub-groups in our dataset. For this we'll encounter the invisible group aesthetic.

mtcars has been given an extra column, fcyl, that is the cyl column converted to a proper factor variable.

Instructions 1/2

undefined XP
  • 1
    • Using mtcars, plot mpg vs. wt, colored by fcyl.
    • Add a point layer.
    • Add a smooth stat using a linear model, and don't show the se ribbon.
  • 2
    • Update the plot to add a second smooth stat.
      • Add a dummy group aesthetic to this layer, setting the value to 1.
      • Use the same method and se values as the first stat smooth layer.