Strange space on grid.arrange plot

I am trying to add a footnote to the grid.arrange graph. I presented my idea on 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 this image:

enter image description here

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

+7
r ggplot2 grid
source share
2 answers

Try using bottom instead of sub :

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

enter image description here

+4
source share

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 change the heights until you get a well-deserved interval. I achieved this only parameter, which showed the values โ€‹โ€‹shown:

enter image description here

0
source share

All Articles