IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Intermediate Data Visualization with ggplot2

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

ggplot(Vocab, aes(x = education, y = vocabulary)) +
  stat_smooth(method = "lm", se = FALSE) +
  # Create facets, wrapping by year, using vars()
  ___(___(___))
Modifica ed esegui il codice