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.
This exercise is part of the course
Intermediate Data Visualization with ggplot2
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
ggplot(mtcars, aes(x = mpg, y = car, color = fam)) +
geom_point() +
# Facet rows by gear
___