1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Data Visualization with ggplot2

Exercise

Wrapping for many levels

facet_grid() is fantastic for categorical variables with a small number of levels. Although it is possible to facet variables with many levels, the resulting plot will be very wide or very tall, which can make it difficult to view.

The solution is to use facet_wrap() which separates levels along one axis but wraps all the subsets across a given number of rows or columns.

For this plot, we'll use the Vocab dataset that we've already seen. The base layer is provided.

Since we have many years, it doesn't make sense to use facet_grid(), so let's try facet_wrap() instead.

Instructions 1/3

undefined XP
  • 1

    Add a facet_wrap() layer and specify:

    • The year variable with an argument using the vars() function,
  • 2

    Add a facet_wrap() layer and specify the year variable with a formula notation (~).

  • 3

    Add a facet_wrap() layer and specify:

    • Formula notation as before, and ncol set to 11.