运用ggalluvial包展示微生物优势菌群—冲击图
最近看了一篇微生物的文章,感觉他的图做的很好看!最终发现,ggalluvial包可以做这种冲击图。
Wei R, Ding Y, Gao F, Zhang L, Wang L, Li H, Wang H. Community succession of the grape epidermis microbes of cabernet sauvignon (Vitis vinifera L.) from different regions in China during fruit development. Int J Food Microbiol. 2022 Feb 2;362:109475. doi: 10.1016/j.ijfoodmicro.2021.109475. Epub 2021 Nov 13. PMID: 34798479.

#安装包
install.packages("ggalluvial")
install.packages("tastypie")
library(ggalluvial)
library(ggplot2)
library(ggthemes)
library(tidyverse)
library(ggsci)
library(cowplot)
library(tastypie)
#读入数据
df=read.csv('MCMPphylum.csv',header = T)
head(df)

#设置色盘
mycol<-c(312,77,22,137,428)
mycol<-colors()[rep(mycol,5)] #在colors()里挑选5个颜色
#绘图
ggplot(df, aes(x = Group,y=BD,fill = OTU, #冲击图必备元素:stratum、alluvium
stratum = OTU, alluvium = OTU))+
geom_col(width = 0.4,color="black")+ #width = 0.4柱子的宽度;color="black"柱子边框,无为NA
scale_fill_manual(values = mycol)+
guides(fill=guide_legend(reverse = T,title = NULL,ncol=4))+
labs(x="Sample",y="Relative abundance",size=12)+ #size=12好像没有用
theme_classic()+
theme(legend.position = "bottom")+
scale_y_continuous(expand = c(0,0))+ #纵坐标贴合x轴
geom_flow(width =1/3,alpha = 0.2,knot.pos = 1/4)+ #alpha有没有面积曲线;值越大,颜色越深
theme(axis.text.x=element_text(size=12,vjust = 1), #横纵坐标字体大小
axis.text.y=element_text(size=12,vjust = 1))