Is there any way to control the size of the strips on facets in a ggplot? I tried using strip.background=element_rect(size=n)
but as far as I can tell it didn't actually do anything. Is this even possible?
Asked
Active
Viewed 4,184 times
11

iod
- 7,412
- 2
- 17
- 36
-
5A somewhat unpleasant hack would be to include newlines (`\n`) in the strip text to increase their size. – joran Dec 10 '14 at 17:41
-
1In `element_rect`, size refers to the point size of the bounding line, it won't really help you make the rectangle bigger or smaller. – Gregor Thomas Dec 10 '14 at 17:42
-
1would converting the plot to a `ggplotGrob` `TableGrob` then looking for `strip_` grobs and modifying the `height`element work? I don't have time to test that now, but I know others fiddle at the grob layer, too. – hrbrmstr Dec 10 '14 at 20:43
1 Answers
10
converting the plot to a gtable manually lets you tweak the strip height,
library(ggplot2)
library(gtable)
d <- ggplot(mtcars, aes(x=gear)) +
geom_bar(aes(y=gear), stat="identity", position="dodge") +
facet_wrap(~cyl)
g <- ggplotGrob(d)
g$heights[[3]] = unit(1,"in")
grid.newpage()
grid.draw(g)

baptiste
- 75,767
- 19
- 198
- 294
-
Thanks. I'm new to this - I saw some mentions of ggplotGrob in similar questions, but none that showed this particular change, and I wasn't sure how to approach it. I'll give it a try later today and play around with it. – iod Dec 11 '14 at 18:35
-
Well, it works, but I don't know why. Is there a decent tutorial that can teach me more about how to use these gtables? I can't figure them out... – iod Dec 11 '14 at 18:58
-
2unfortunately there isn't a tutorial, and gtable developers have moved on to new projects. The best reference is probably here, browsing the [gtable tag](http://stackoverflow.com/questions/tagged/gtable). I started writing [some doc](https://github.com/baptiste/gtable/wiki/Description), but quite frankly I lost motivation seeing that the developers wouldn't accept pull requests. – baptiste Dec 11 '14 at 19:32
-
1