Skip to content

Instantly share code, notes, and snippets.

@aqd14
Created April 14, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aqd14/6ab9a5540ec269852cd7ea3dcaad3517 to your computer and use it in GitHub Desktop.
Save aqd14/6ab9a5540ec269852cd7ea3dcaad3517 to your computer and use it in GitHub Desktop.
When we `fill` the plot with `gender`, it implicitly groups the data according to `gender`. Using `interaction` to tell `ggplot` to group data by both variables.
grand_slam_ages %>%
mutate(decade = 10 * (year %/% 10)) %>%
ggplot(aes(decade, age, fill = gender, group = interaction(decade, gender))) +
geom_boxplot() +
scale_x_continuous(breaks = seq(1950, 2021, 10)) +
expand_limits(x = 2020)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment