我想删除默认情况下在grid.arrange中的图和表之间插入的大间距,如下面的MWE所示:
require(ggplot2)
require(gridExtra)
list1=data.frame(mtcars[1:3, ]) # Dummy data
p1 = ggplot(list1, aes(mpg,cyl)) + geom_point() # Dummy plot
p2 = ggplot(list1, aes(disp,hp)) + geom_point() # Dummy plot
plots <- arrangeGrob(p1, p2,nrow=2)
table <- tableGrob(list1)
grid.arrange(plots, table)
Run Code Online (Sandbox Code Playgroud)
我怀疑这种行为是由于tableGrob引起的,但我找不到任何解决这个问题的答案.
提前致谢!
grid.arrange()默认情况下为每个单元格分配相等的空间.如果你想在特定的grob周围紧密配合,你应该查询它的大小,并明确地传递它,
library(grid)
th <- sum(table$heights) # note: grobHeights.gtable is inaccurate
grid.arrange(plots, table, heights = unit.c(unit(1, "null"), th))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7964 次 |
| 最近记录: |