如何在ggplot中更改小平面上的条带大小?

时间:2014-12-10 17:36:48

标签: r ggplot2

有没有办法控制ggplot中刻面上条带的大小?我尝试使用strip.background=element_rect(size=n),但据我所知,它实际上没有做任何事情。这甚至可能吗?

1 个答案:

答案 0 :(得分:10)

手动将绘图转换为gtable,可以调整条带高度

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)