微生物功能多样性:R语言

文摘   2024-12-29 21:55   甘肃  
本视频主要讲解微生物群落功能多样性指数的计算,涉及Rao二次熵指数(Rao’s Q)、功能丰富度指数(FRic)、功能均匀度指数(FEve)、功能分异指数(FDiv)、功能分散指数(FDis)计算及绘图。
示例数据(文末获取)
物种数据

功能数据

分组数据

代码如下
#代码在微信公众号,不懂绘图中,请自己翻历史图文消息。#相关运行问题请加qq群341596698#也接代做的rm(list=ls())library(fundiversity)library(ggplot2)library(ggsci)library(ggsignif)library(gghalves)library(reshape2)#导入物种丰度数据spe <- read.csv("F:/sp.csv",row.names = 1,header = T)head(spe)#导入物种性状数据xz <- read.csv("F:/xz.csv",row.names = 1,header = T)head(xz)#导入分组文件group <- read.csv("F:/group.csv",row.names = 1,header = T)#这里要注意,得转化数据框xz<-as.matrix(xz)spe<-as.matrix(spe)#功能分散指数(FDis)FDis<-fd_fdis(xz, spe)FDis#功能分异指数(FDiv)FDiv<-fd_fdiv(xz, spe)FDiv#功能均匀度指数(FEve)FEve<-fd_feve(xz, spe)FEve#功能丰富度指数(FRic)FRic<-fd_fric(xz, spe)FRic#Rao二次熵指数(Rao’s Q)Rao<-fd_raoq(xz, spe)Rao#开始绘图#FDisFDisdata<-cbind(FDis, group)FDisdatap<-ggplot(FDisdata,aes(group,FDis,fill=group))+  geom_half_violin(position = position_nudge(x=0.25),                   side = "r",width=0.8,color=NA)+  geom_boxplot(width=0.4,size=1.2,outlier.color =NA)+  geom_jitter(aes(fill=group),shape=21,size=2.5,width=0.2)+  geom_signif(comparisons = list(c("A","B"),                                 c("A","C"),                                 c("B","C")),              map_signif_level = T,              test = t.test,#显著性检验方法,可选具体选择可看我之前的关于多样性的视频              y_position = c(165,175,185),#这里写显著性标记的位置和高度              size=1,color="black",textsize = 4)+#这里写显著性的字体大小  scale_y_continuous(limits = c(60,190),#这里设置一下y轴最低和最高的刻度                     breaks = c(60,95,125,155,190))+#这里设置一下y轴刻度增量  theme_bw()+  theme(panel.grid = element_blank(),        panel.border = element_rect(size = 1),        axis.text.x = element_text(color = "black", size = 13),        axis.text.y = element_text(color = "black",size = 13),        legend.position = "none",        axis.ticks = element_line(color="black",linewidth = 1))+  labs(x=NULL,y=NULL)+  scale_fill_manual(values = c("#99e5f3","#e6a84b","#efdcb1"))p#FDivFDivdata<-cbind(FDiv, group)FDivdatap1<-ggplot(FDivdata,aes(group,FDiv,fill=group))+  geom_half_violin(position = position_nudge(x=0.25),                   side = "r",width=0.8,color=NA)+  geom_boxplot(width=0.4,size=1.2,outlier.color =NA)+  geom_jitter(aes(fill=group),shape=21,size=2.5,width=0.2)+  geom_signif(comparisons = list(c("A","B"),                                 c("A","C"),                                 c("B","C")),              map_signif_level = T,              test = t.test,#显著性检验方法,可选具体选择可看我之前的关于多样性的视频              y_position = c(0.75,0.76,0.77),#这里写显著性标记的位置和高度              size=1,color="black",textsize = 4)+#这里写显著性的字体大小  scale_y_continuous(limits = c(0.63,0.78),#这里设置一下y轴最低和最高的刻度                     breaks = c(0.63,0.7,0.78))+#这里设置一下y轴刻度增量  theme_bw()+  theme(panel.grid = element_blank(),        panel.border = element_rect(size = 1),        axis.text.x = element_text(color = "black", size = 13),        axis.text.y = element_text(color = "black",size = 13),        legend.position = "none",        axis.ticks = element_line(color="black",linewidth = 1))+  labs(x=NULL,y=NULL)+  scale_fill_manual(values = c("#99e5f3","#e6a84b","#efdcb1"))p1#FEveFEvedata<-cbind(FEve, group)FEvedatap2<-ggplot(FEvedata,aes(group,FEve,fill=group))+  geom_half_violin(position = position_nudge(x=0.25),                   side = "r",width=0.8,color=NA)+  geom_boxplot(width=0.4,size=1.2,outlier.color =NA)+  geom_jitter(aes(fill=group),shape=21,size=2.5,width=0.2)+  geom_signif(comparisons = list(c("A","B"),                                 c("A","C"),                                 c("B","C")),              map_signif_level = T,              test = t.test,#显著性检验方法,可选具体选择可看我之前的关于多样性的视频              y_position = c(0.44,0.46,0.48),#这里写显著性标记的位置和高度              size=1,color="black",textsize = 4)+#这里写显著性的字体大小  scale_y_continuous(limits = c(0.25,0.5),#这里设置一下y轴最低和最高的刻度                     breaks = c(0.25,0.3,0.35,0.4,0.5))+#这里设置一下y轴刻度增量  theme_bw()+  theme(panel.grid = element_blank(),        panel.border = element_rect(size = 1),        axis.text.x = element_text(color = "black", size = 13),        axis.text.y = element_text(color = "black",size = 13),        legend.position = "none",        axis.ticks = element_line(color="black",linewidth = 1))+  labs(x=NULL,y=NULL)+  scale_fill_manual(values = c("#99e5f3","#e6a84b","#efdcb1"))p2

讲解视频如下

出图如下

示例文件
通过网盘分享的文件:功能多样性.zip

链接: https://pan.baidu.com/s/1pNEN7Eh33HJTnzzUu8a3oQ 提取码: 342k

麦当的生态学笔记
用于文献信息解读和分享,统计分析相关方法的传递。
 最新文章