Zhang
Zhang

Reputation: 23

How to change the height of the strip on facets with 2 rows

I used the following code to change the height of the strip background on facets. But it seemed not efficient for the second row.

library(reshape2)
library(grid)
library(gtable)
library(ggplot2)

gp <- ggplot(data = tips, aes(x = total_bill, y = tip/total_bill)) + geom_point() + facet_wrap( ~ day, ncol = 2)

g <- ggplotGrob(gp)
g$heights[[3]] = unit(0.3, 'in')
g$grobs[[6]]$heights <- g$grobs[[7]]$heights <- g$grobs[[8]]$heights <- g$grobs[[9]]$heights <- unit(1, 'native')
grid.draw(g)

Obtained result

Expected result

Upvotes: 1

Views: 315

Answers (1)

TheRimalaya
TheRimalaya

Reputation: 4592

g$heights[c(3,7)] <- unit(0.3, 'in')

Upvotes: 1

Related Questions