如何使用2行更改小平面上的条带高度

时间:2016-04-09 15:58:20

标签: r ggplot2 facet

我使用以下代码更改构面上条带背景的高度。但是第二排似乎效率不高。

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

1 个答案:

答案 0 :(得分:1)

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