Exercise

Variable plotting spaces II: categorical variables

When you have a categorical variable with many levels which are not all present in each sub-group of another variable, it's usually desirable to drop the unused levels.

By default, each facet of a plot is the same size. This behavior can be changed with the spaces argument, which works in the same way as scales: "free_x" allows different sized facets on the x-axis, "free_y", allows different sized facets on the y-axis, "free" allows different sizes in both directions.

Instructions 1/2

undefined XP
  • 1
    • Facet the plot by rows according to gear using vars(). Notice that every car is listed in every facet, resulting in many lines without data.
  • 2
    • To remove blank lines, set the scales and space arguments in facet_grid() to free_y.