justinian482
justinian482

Reputation: 1075

Putting factors together in data frame R

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?

Upvotes: 2

Views: 43

Answers (1)

teunbrand
teunbrand

Reputation: 37933

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)

Upvotes: 2

Related Questions