I combined some ideas from the comments in your question. You can set the limits to be the same on the x and y axes as well - I did not do it here because I was not sure if it was important to your question,
library(plyr)
library(foreach)
library(ggplot2)
library(dplyr)
library(gridExtra)
dat <- foreach(i = 1:6, .combine = rbind) %do% {
data.frame(x = rnorm(1000), y = rnorm(1000), fac = as.factor(i))
}
#update: added 7th part to the layer matrix for the legend
lay <- rbind(c(1,1,1,1,2,2,7),c(1,1,1,1,2,2,7),
c(1,1,1,1,3,3,7),c(1,1,1,1,3,3,7),
c(4,4,5,5,6,6,7),c(4,4,5,5,6,6,7))
gp1 <- ggplot(filter(dat, fac ==1), aes(x=x, y = y))+
geom_point(aes(col = x+y))+
#set limits the same on each graph or color gradient
scale_color_gradient(limits = c(min(dat$x + dat$y),max(dat$x + dat$y)))
gp2 <- ggplot(filter(dat, fac ==2), aes(x=x, y = y))+
geom_point(aes(col = x+y))+
scale_color_gradient(limits = c(min(dat$x + dat$y),max(dat$x + dat$y)))
gp3 <- ggplot(filter(dat, fac ==3), aes(x=x, y = y))+
geom_point(aes(col = x+y))+
scale_color_gradient(limits = c(min(dat$x + dat$y),max(dat$x + dat$y)))
gp4 <- ggplot(filter(dat, fac ==4), aes(x=x, y = y))+
geom_point(aes(col = x+y))+
scale_color_gradient(limits = c(min(dat$x + dat$y),max(dat$x + dat$y)))
gp5 <- ggplot(filter(dat, fac ==5), aes(x=x, y = y))+
geom_point(aes(col = x+y))+
scale_color_gradient(limits = c(min(dat$x + dat$y),max(dat$x + dat$y)))
gp6 <- ggplot(filter(dat, fac ==6), aes(x=x, y = y))+
geom_point(aes(col = x+y))+
scale_color_gradient(limits = c(min(dat$x + dat$y),max(dat$x + dat$y)))
# grab legend from one plot
g_legend<-function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
return(legend)}
aleg <- g_legend(gp1)
gp1 <- gp1+ theme(legend.position = "none")
gp2 <- gp2+ theme(legend.position = "none")
gp3 <- gp3+ theme(legend.position = "none")
gp4 <- gp4+ theme(legend.position = "none")
gp5 <- gp5+ theme(legend.position = "none")
gp6 <- gp6 + theme(legend.position = "none")
gpls <- lapply(list(gp1,gp2, gp3,gp4,gp5,gp6), ggplotGrob )
gridExtra::grid.arrange(gpls[[1]], gpls[[2]],
gpls[[3]], gpls[[4]],
gpls[[5]], gpls[[6]],
#use layout matrix to set sizes
layout_matrix=lay, aleg)
Edit - Added plot to answer.
