Putting factors together in data frame R

Viewed 36

I have got a data frame of which one column contains 5 factors and I have used ggplot2 to plot a facet_grid and this plots 5 graphs with each one of them containing data from each of the factors. However I want to include an extra facet that contains the combined data of all the factors. How would I do this?

1 Answers

For facet_grid() you can set margins = TRUE. Shown with standard dataset below:

library(ggplot2)

ggplot(mpg, aes(hwy, cty)) +
  geom_point() +
  facet_grid(~ drv, margins = TRUE)

Related