MatthewTadesse
MatthewTadesse

Reputation: 31

Add titles to facets

I've made a faceted a box plot using two variables. How can I put headers for the facet?

library(ggplot2)
ggplot(data = data60 ,aes(x = education_level, y = lw)) +
   geom_boxplot() + 
   facet_grid(rns~smsa) +
   labs(x = "Education Level", y = "Log Wage") + 
   theme_bw()

Upvotes: 1

Views: 176

Answers (1)

jay.sf
jay.sf

Reputation: 72994

You may newly create a factor variable out of your facet variable and use it to facet.

Example

library(ggplot2)
mpg$drv.f <- factor(mpg$drv, labels=c("label1", "label2", "label3"))
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
p + facet_grid(rows = vars(drv.f))

enter image description here

Upvotes: 2

Related Questions