❝本节来进行论文图表的复现,下面来介绍NC上一张菌种组成图的绘制方法,在作者原有的基础上做了一些细微的改动,下面来看具体案例;
❝A highly conserved core bacterial microbiota with nitrogen-fixation capacity inhabits the xylem sap in maize plants ❞
加载R包
代码语言:javascript复制library(tidyverse)
library(ggh4x)
导入数据
代码语言:javascript复制sub_merge <- read_tsv("data.txt")
定义因子
代码语言:javascript复制sub_merge$Compartments <- factor(sub_merge$Compartments,levels=c("BS","RS","RE","VE","SE","LE","P"),
labels = c("BS", "RS","RE","VE","SE","LE","P"))
sub_merge$Phylum<-factor(sub_merge$Phylum,levels=c("Abditibacteriota", "Acidobacteriota",
"Actinobacteriota","Alphaproteobacteria",
"Bacteroidota","Chloroflexi","Deinococcota",
"Firmicutes","Gammaproteobacteria","Gemmatimonadota",
"Myxococcota","Nitrospirota","unclassified","Others"),
labels = c("Abditibacteriota", "Acidobacteriota", "Actinobacteriota","Alphaproteobacteria",
"Bacteroidota","Chloroflexi","Deinococcota","Firmicutes","Gammaproteobacteria",
"Gemmatimonadota","Myxococcota","Nitrospirota","unclassified","Others"))
自定义数据
代码语言:javascript复制phy.cols <- c("#FF6A6A","#FF8247","#FFE7BA","#87CEFA","#B0E0E6","#48D1CC","#5F9EA0","#66CDAA",
"#458B00","#BCEE68","#FFF68F","#EEEE00","#FFFFE0","#8B8682")
数据可视化
代码语言:javascript复制ggplot(sub_merge, aes(x = TreatmentID,y=`Relative abundance (%)`,fill=Phylum))
geom_bar(stat='identity', position = "fill")
labs(x="Treatment",y="Relative abundance")
facet_nested(Soiltype Site~Compartments,drop=T,scale = "free",space="free")
scale_y_continuous(expand=c(0,0),labels=scales::percent)
theme_bw()
theme(axis.text.x = element_blank(),
axis.ticks.x=element_blank(),
axis.text.y = element_text(size = 8,color="black"),
axis.title.y= element_text(size=12,color="black"),
axis.title.x = element_text(size = 12),
legend.title=element_text(size=12),
legend.text=element_text(size=10),
legend.position = "bottom",
panel.spacing.x=unit(0,"lines"),
panel.spacing.y=unit(0.5,"lines"))
scale_fill_manual(values=phy.cols)
❝好了本节介绍到此结束,整个代码还是非常简洁的