I have a couple of ggplot plots that I want to merge using grid.arrange()

When I merge the plots there's a large white area around each plot making them far away from each other.

Is there a way to adjust the distance between the plots? and the size of the white area around the plots?

有帮助吗?

解决方案

You can use theme(plot.margin) function in ggplot2 to reduce the spacing.

A simple working example here :

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

x <- seq(1,10,1)
y <- dnorm(x,mean=10,sd=0.5)


 # Create p1
p1 <- qplot(x,y) + theme(plot.margin=unit(c(1,1,-0.5,1),"cm"))

# Create p2
p2 <- qplot(x,y) + theme(plot.margin=unit(c(-0.5,1,1,1),"cm"))

grid.arrange(p1,p2)

Edit The four numbers are c(bottom,left,top,right)

Sample output

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top