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.
Deze oefening maakt deel uit van de cursus
Intermediate Data Visualization with ggplot2
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
ggplot(Vocab, aes(x = education, y = vocabulary)) +
stat_smooth(method = "lm", se = FALSE) +
# Create facets, wrapping by year, using vars()
___(___(___))