R geom_瓷砖地块的垂直对齐
我有来自三个不同研究的数据,我正在使用R geom_瓷砖地块的垂直对齐,r,ggplot2,gridextra,R,Ggplot2,Gridextra,我有来自三个不同研究的数据,我正在使用ggplot2的geom\u tile绘制这些数据。列为category-绘制在y轴上,x-绘制在x轴上,以及score-将对瓷砖进行颜色编码。研究列指定了研究 以下是数据: library(dplyr) set.seed(1) df <- data.frame(category=strsplit("Peptide,Amino Acid,Nucleotide,Xenobiotics,Carbohydrate,Cofactors and Vitamins
ggplot2
的geom\u tile
绘制这些数据。列为category
-绘制在y轴上,x
-绘制在x轴上,以及score
-将对瓷砖进行颜色编码。研究
列指定了研究
以下是数据:
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)
然后,我尝试使用gridExtra
的arrangeGrob
函数将它们放在一个图形中,我希望它们垂直对齐,但这似乎不起作用:
library(gridExtra)
combined.plot <- gridExtra::arrangeGrob(grobs=list(plot1,plot2,plot3),ncol=1,nrow=3)
库(gridExtra)
combined.plot您可以使用软件包ggpubr
中的函数ggarrange
:
ggpubr::ggarrange(plot1, plot2, plot3, nrow = 3, align = "v")
附言:
- 使用
egg::ggarrange
可以获得类似的结果,但是它使绘图B的y-lab不对齐(未添加空白):egg::ggarrange(绘图1、绘图2、绘图3)
- 不要在所有绘图中键入,您可以使用参数
plotlist
和函数mget
:ggpubr::ggarrange(plotlist=mget(粘贴0(“绘图”,1:3)),nrow=3,align=“v”)
我建议在这3项研究中使用方面。
ggpubr::ggarrange(plot1, plot2, plot3, nrow = 3, align = "v")