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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
xandyaxis labels to NULL inlabsbut 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: