peter_c
peter_c

Reputation: 91

Strange space on grid.arrange plot

I am trying to add footnote to grid.arrange graph. I presented my idea in this reproducible example: )

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)

This code generates that picture:

enter image description here

with huge space below the graphs. How to get rid off of that? Why is it created?

Upvotes: 7

Views: 1841

Answers (2)

User 6683331
User 6683331

Reputation: 710

One easy way is to use this code:

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

And modify the heights until you have the deserved spacing. I achieved this only setting that parameter with showed values:

enter image description here

Upvotes: 0

erc
erc

Reputation: 10123

Try using bottom instead of sub:

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

enter image description here

Upvotes: 4

Related Questions