grid.arrange图上的奇怪空间

时间:2016-03-23 10:44:25

标签: r ggplot2 r-grid

我正在尝试为grid.arrange图添加脚注。我在这个可重复的例子中提出了我的想法: )

library(ggplot2)
library(gridExtra)
library(grid)
library(gtable)

summary(anscombe)

p1 <- ggplot(anscombe) + geom_point(aes(x1, y1), color = "darkorange", size = 3) + theme_bw() 

p2 <- ggplot(anscombe) + geom_point(aes(x2, y2), color = "darkorange", size = 3) + theme_bw()

p3 <- ggplot(anscombe) + geom_point(aes(x3, y3), color = "darkorange", size = 3) + theme_bw()

p4 <- ggplot(anscombe) + geom_point(aes(x4, y4), color = "darkorange", size = 3) + theme_bw() 

title <- textGrob("Some title",
              gp=gpar(fontsize=20,fontface=2))

source1<- textGrob("Source: https://rpubs.com/neilfws/91339",
              hjust=0,x=0,y=1,
              gp=gpar(fontsize=10,fontface=3))

grid.arrange(arrangeGrob(p1,p2,p3,p4, ncol=2, sub = source1), top = title)

此代码生成该图片:

enter image description here

图表下面有很大的空间。如何摆脱这种局面?它为什么创建?

2 个答案:

答案 0 :(得分:4)

尝试使用bottom代替sub

grid.arrange(arrangeGrob(p1,p2,p3,p4, ncol=2, bottom = source1), top = title)

enter image description here

答案 1 :(得分:0)

一种简单的方法是使用此代码:

grid.arrange(arrangeGrob(p1,p2,p3,p4, ncol=2, sub = source1), top = title, heights = c(50,-15))

修改高度,直到你得到应得的间距。我实现了这个只设置该参数显示值:

enter image description here