Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to increase the height of the strip.text bar in a facet?

Tags:

r

ggplot2

I would like the grey bar at the top to be wider, as in, have the edges of it a little further from the top and bottom of the letters (the strip.text - A, B, C etc). I would have thought the lineheight would have acted as padding but it doesn't.

ggplot(diamonds, aes(carat, price, fill = ..density..)) +
  xlim(0, 2) + stat_binhex(na.rm = TRUE)+
  facet_wrap(~ color) +
  theme(strip.text = element_text(lineheight=20)) 
like image 717
nzcoops Avatar asked Jul 24 '13 04:07

nzcoops


1 Answers

First, modify the levels so that they include a linebreak:

levels(diamonds$color) <- paste0(" \n", levels(diamonds$color) , "\n ")

Then adjust as necessary. eg:

P <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
      xlim(0, 2) + stat_binhex(na.rm = TRUE)+
      facet_wrap(~ color)

P +  theme(strip.text = element_text(size=9, lineheight=0.5))

lineheight=0.5

P +  theme(strip.text = element_text(size=9, lineheight=3.0))

lineheight=3.0

like image 121
Ricardo Saporta Avatar answered Oct 06 '22 17:10

Ricardo Saporta