3

I am using facet_grid in package "ggplot2" to facet columns by two variables. Each facet gets two header stips - one for each conditioning variable. Each value of the first variable is repeated for all levels of the second variable. I would like to know if I could have a single header for the first variable spread across all levels of the second variable.

Here is a toy example:

dat <- expand.grid(x=c(0,1), A=c("a1","a2"), B=c("b1","b2","b3"))
dat$y <- rnorm(nrow(dat))
ggplot(dat, aes(x, y)) + geom_point() + facet_grid(~A+B)

Each level of A is repeated in 3 consecutive headers - one for each level of B. I would like to have just two header strips for A - one covering the first 3 panels, and another for the second 3 panels.

Does anyone know if/how this can be done?

bdemarest
  • 14,397
  • 3
  • 53
  • 56
  • The `labeller` option with a custom function is the solution; https://github.com/hadley/ggplot2/wiki/labeller is your friend for more background info how to implement it. – Paul Lemmens Sep 23 '14 at 06:44
  • 1
    Are you asking for this answer? http://stackoverflow.com/questions/11353287/how-do-you-add-a-general-label-to-facets-in-ggplot2 – CMichael Sep 23 '14 at 10:49
  • 1
    Possible duplicate of [How do you add a general label to facets in ggplot2?](https://stackoverflow.com/questions/11353287/how-do-you-add-a-general-label-to-facets-in-ggplot2) – Nakx Dec 05 '18 at 05:17

0 Answers0