#代码在微信公众号,不懂绘图中,请自己翻历史图文消息。
#相关运行问题请加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
#开始绘图
#FDis
FDisdata<-cbind(FDis, group)
FDisdata
p<-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
#FDiv
FDivdata<-cbind(FDiv, group)
FDivdata
p1<-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
#FEve
FEvedata<-cbind(FEve, group)
FEvedata
p2<-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
链接: https://pan.baidu.com/s/1pNEN7Eh33HJTnzzUu8a3oQ 提取码: 342k