6
require(ggplot2)
ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_grid(vs+gear ~ cyl+am) 

enter image description here

I would like to add the name of the 4 variables used for facet_grid on this graph. I suppose the best way to do so would be to add the name of the variables in the corners with a small arrow pointing to the row or column. I was thinking to use annotation_custom and textGrob for this purpose but failed to get anything printed on the graph.

Remi.b
  • 17,389
  • 28
  • 87
  • 168
  • 2
    Have you looked at `facet_grid(vs+gear ~ cyl+am, labeller = label_both)`? Not quite the same, but gets the info on the graph. – aosmith Sep 16 '16 at 18:45

1 Answers1

7

Something like this?

ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_grid(vs+gear ~ cyl+am,labeller = labeller(.rows = label_both, .cols = label_both))

You can also use syntax like so:

labeller = label_bquote("Gear"==.(gear))
Dan Slone
  • 543
  • 2
  • 8