删除grid.arrange中绘图和表格之间的空白
我想删除默认情况下在grid.arrange中的绘图和表格之间插入的大间距,如下文所示:删除grid.arrange中绘图和表格之间的空白,r,gridextra,grob,R,Gridextra,Grob,我想删除默认情况下在grid.arrange中的绘图和表格之间插入的大间距,如下文所示: 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 plo
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)
require(ggplot2)
需要(额外)
list1=数据帧(mtcars[1:3,])#虚拟数据
p1=ggplot(列表1,aes(mpg,cyl))+geom_点()
p2=ggplot(列表1,aes(显示,hp))+geom_点()
plots我实际上找到了控制grob之间间距的参数:heights,见下一行
grid.arrange(plots, table, heights=c(5,1))
默认情况下,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))
库(网格)
这会有帮助吗?不完全是这样,它在两个ggplot之间的行为与在plot和tableGrob之间的行为不同。但是谢谢!此答案的可能重复项使我失败,原因是:排列中出现错误(…):找不到函数“unit.c”