I have data from three different studies which I'm plotting using ggplot2's geom_tile. The columns are category - to be plotted on the y-axis, x - the x-axis, and score - which will be color coding the tiles. The study column specifies the study.
Here are the data:
library(dplyr) set.seed(1) df <- data.frame(category=strsplit("Peptide,Amino Acid,Nucleotide,Xenobiotics,Carbohydrate,Cofactors and Vitamins,Lipid,Lysophospholipid,Gamma-glutamyl Amino Acid,Leucine Isoleucine and Valine Metabolism,Fatty Acid Dicarboxylate,Long Chain Fatty Acid,Sterol,Secondary Bile Acid Metabolism,Polyunsaturated Fatty Acid (n3 and n6),Other Tentative Assignments,Energy,Cofactors And Vitamins,Sulfur Metabolism,Amino Acids,Carnitine And Fatty Acid Metabolsim,Glycerophospholipid Biosynthesis,Stimulating/Exogenous Compounds,Carboxylic Acid,Bile Acids,Gamma-Glutamyls,Arachidonate Metabolism,Gsh Homeostasis,Medium Chain Fatty Acid,Urea cycle; Arginine and Proline Metabolism",split=",")[[1]], x=rep("x",30),score=log10(runif(30,0,1)),study=c(rep("study1",12),rep("study2",10),rep("study3",8)),stringsAsFactors = F) I'm plotting each study separately using geom_tile, but defining the width argument in geom_tile to be 0.5 for all three plots:
library(ggplot2) plot1 <- ggplot(data=df %>% dplyr::filter(study == "study1"),aes(x=x,y=category))+geom_tile(aes(fill=score),width=0.5)+ scale_fill_gradient2(low='darkblue',mid='white',high='darkred')+ theme_minimal()+xlab("")+labs(fill="score")+ylab("Pathway")+ theme(axis.text.x=element_blank(),plot.title=element_text(size=16,hjust=0,face="bold"),axis.title=element_text(size=18,face="bold"),axis.text=element_text(size=16),legend.text=element_text(size=16),legend.title=element_text(size=16,face="bold"))+ggtitle("A.") plot2 <- ggplot(data=df %>% dplyr::filter(study == "study2"),aes(x=x,y=category))+geom_tile(aes(fill=score),width=0.5)+ scale_fill_gradient2(low='darkblue',mid='white',high='darkred')+ theme_minimal()+xlab("")+labs(fill="score")+ylab("Pathway")+ theme(axis.text.x=element_blank(),plot.title=element_text(size=16,hjust=0,face="bold"),axis.title=element_text(size=18,face="bold"),axis.text=element_text(size=16),legend.text=element_text(size=16),legend.title=element_text(size=16,face="bold"))+ggtitle("B.") plot3 <- ggplot(data=df %>% dplyr::filter(study == "study3"),aes(x=x,y=category))+geom_tile(aes(fill=score),width=0.5)+ scale_fill_gradient2(low='darkblue',mid='white',high='darkred')+ theme_minimal()+xlab("")+labs(fill="score")+ylab("Pathway")+ theme(axis.text.x=element_blank(),plot.title=element_text(size=16,hjust=0,face="bold"),axis.title=element_text(size=18,face="bold"),axis.text=element_text(size=16),legend.text=element_text(size=16),legend.title=element_text(size=16,face="bold"))+ggtitle("C.") Then, I'm trying to put them in a single figure using gridExtra's arrangeGrob function, where I want them aligned vertically but that doesn't seem to work:
library(gridExtra) combined.plot <- gridExtra::arrangeGrob(grobs=list(plot1,plot2,plot3),ncol=1,nrow=3) Because this is what I'm getting:
So my question is how to create a figure where the three plots come out with exactly the same tile widths and aligned vertically (i.e., the tiles are aligned rather than the long category text).

