Reputation: 18219
require(ggplot2)
ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_grid(vs+gear ~ cyl+am)
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.
Upvotes: 8
Views: 3257
Reputation: 563
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))
Upvotes: 7