26

What I'd like it's to remove those labels on the right side, the ones on gray boxes on the side. I'll give an example:

p <- ggplot(mtcars, aes(mpg, wt, col=factor(cyl))) + geom_point()
p + facet_grid(cyl ~ .)

enter image description here

Thanks in advance!

Juan

Juan
  • 1,351
  • 1
  • 14
  • 28
  • Possible duplicate of http://stackoverflow.com/questions/10547487/r-removing-facet-wrap-labels-completely-in-ggplot2 – Curt F. Mar 27 '15 at 15:11

1 Answers1

53

The following would do that:

p <- ggplot(mtcars, aes(mpg, wt, col=factor(cyl))) + geom_point()
p <- p + facet_grid(cyl ~ .)
p <- p +theme(strip.text.y = element_blank())

Without rectangles

p <- ggplot(mtcars, aes(mpg, wt, col=factor(cyl))) + geom_point()
p <- p + facet_grid(cyl ~ .)
p <- p + theme(strip.background = element_blank(),
   strip.text.y = element_blank())

enter image description here

Ruthger Righart
  • 4,799
  • 2
  • 28
  • 33
  • 3
    Perhaps like this? `ggplot(mtcars, aes(mpg, wt, col=factor(cyl))) + geom_point() + facet_grid(cyl ~ .) + theme(strip.text.y = element_blank(), strip.background = element_blank())` – Fredrik Karlsson Mar 27 '15 at 15:20
  • This is a good pointer, however, there are still gray rectangles on the side, any way to erase those? – Juan Mar 27 '15 at 15:27
  • Nice one @FredrikKarlsson! That's definitively it. – Juan Mar 27 '15 at 15:35
  • @Fredrik Karlsson: thank you for your suggestion, I updated that in the answer box, if your permit of course ;-) – Ruthger Righart Mar 27 '15 at 15:48
  • 4
    Is it me or this is not working for the following (lifted from ggplot manual): ``ggplot(economics_long, aes(date, value)) + geom_line() + facet_wrap(~variable, scales = "free_y", nrow = 2) + theme(strip.background = element_blank(), strip.text.y = element_blank())`` – PatrickT Oct 06 '17 at 09:25