I wonder how to add facet titles in ggplot2
ggplot(diamonds, aes(cut)) + geom_bar() + facet_grid(color ~ clarity)
and change the legend title
ggplot(diamonds, aes(cut, fill=cut)) + geom_bar() + facet_grid(. ~ clarity)
Thanks for your help.
The facets are labeled using the levels of the factor used. So if you simply change the levels , such as
those facets will now be labeled using those letters. The legend title matches the label for that aesthetic mapping, which you can set via:
As an extra tidbit, I've noticed that I can set the
x
andy
axis labels to NULL inlabs
but not the legend titles; for those you use an empty character if you want no title.Edit
Given your clarifications, you can add text outside the plotting area using
grid.text
: