I'm trying to produce side by side tile plots using ggplot2 and gridExtra. However, the plots produced are not scaled/aligned, see the picture and code below.
How can I produce this figure such that the cells are aligned and of the same dimensions?
library(ggplot2)
library(gridExtra)
## make date frames
one <- floor(runif(56, min=0, max=5))
data.one<- cbind(one,expand.grid(h = seq(1,8,1), w = seq(1,7,1)))
two <- floor(runif(35, min=0, max=5))
data.two <- cbind(two,expand.grid(h = seq(1,7,1), w = seq(1,5,1)))
## gridExtra layout
lay <- rbind(c(1,1,1,1,1,1,1,NA,NA,NA,NA,NA),
c(1,1,1,1,1,1,1,2,2,2,2,2),
c(1,1,1,1,1,1,1,2,2,2,2,2),
c(1,1,1,1,1,1,1,2,2,2,2,2),
c(1,1,1,1,1,1,1,2,2,2,2,2),
c(1,1,1,1,1,1,1,2,2,2,2,2),
c(1,1,1,1,1,1,1,2,2,2,2,2),
c(1,1,1,1,1,1,1,2,2,2,2,2))
##plots
plot.one<-ggplot(data=data.one)+
geom_tile(aes(x=w,y=h,fill=one),colour = "grey50")+
scale_fill_gradient(low = "white", high = "blue")+
theme(legend.position= "none")
plot.two<-ggplot(data=data.two)+
geom_tile(aes(y=h,x=w,fill=two),colour = "grey50")+
scale_fill_gradient(low = "white", high = "red")+
theme(legend.position= "none")
grid.arrange(plot.one,plot.two, layout_matrix = lay)
cowplot
—it's got some solutions to simplify this type of situation, and is well-documented – camille