1

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()
David Arenburg
  • 91,361
  • 17
  • 137
  • 196
  • 1
    Since we can't run your code without data, and we can't see any output, it's unclear what you have and what you're trying to change. Try to make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so it's easier to help – camille Jan 01 '20 at 18:39

1 Answers1

2

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

jay.sf
  • 60,139
  • 8
  • 53
  • 110