library(ggplot2)
library(vegan)
Arf=read.csv("Arf.csv",sep=",",header=T,row.names=1)
Com=read.csv("Com.csv",sep=",",header=T,row.names=1)
Sti=read.csv("Ste.csv",sep=",",header=T,row.names=1)
Cle=read.csv("cle.csv",sep=",",header=T,row.names=1)
#做相关性分析,将环境因子与变量合并
Sti.cor<-cor(Sti)
Cle.cor<-cor(Cle)
Arf.cor<-cor(Arf)
Com.cor<-cor(Com)
#删除NA的变量
#删除列,会报错但是已经删除NA项
Arf.cor[,-which(names(Arf.cor)%in%c("Aquincola.")]
Arf.cor=subset(Arf.cor,select=-c(Aquincola.))
Arf=subset(Arf,select=-c(Aquincola.))
Arf[,-which(names(Arf)%in%c("Aquincola.")]
#删除行
#fix(Com),交互式界面,可以复制粘贴数据框文本与数据
Arf.cor=Arf.cor[complete.cases(Arf.cor),]
Com.cor[,-which(names(Com.cor)%in%c("Paenibacillus")]
Com.cor=subset(Com.cor,select=-c(Paenibacillus))
Com[,-which(names(Com)%in%c("Paenibacillus")]
Com=subset(Com,select=-c(Paenibacillus))
Com.cor=Com.cor[complete.cases(Com.cor),]
library(vcd)
library(corrplot)
library(psych)
#将四幅图组合在一张图中,方法一
#matrix中的数字就是分割后的图像区域的序数
pdf("R.pdf",width=6,height=8)
layout(matrix(c(1,2,3,4), nrow=2, byrow = F),widths=c(2,2),heights=c(2,2))
opar<- par(no.readonly=TRUE)
#设置图边距及缩放0.5
par(mai=c(0.6,0.4,0.1,0.1),cex=0.3)
#查看画布布局
layout.show(4)
Sti.test=corr.test(Sti, use = "complete")
sig.Sti <- cor.mtest(Sti, conf.level = .95)
Cle.test=corr.test(Cle, use = "complete")
sig.Stile <- cor.mtest(Cle, conf.level = .95)
Arf.test=corr.test(Arf, use = "complete")
sig.Arf <- cor.mtest(Arf, conf.level = .95)
Com.test=corr.test(Com, use = "complete")
sig.Stiom<- cor.mtest(Com, conf.level = .95)
#Arfh.cex=1.2,表示显著性标记的大小
Sti.cor.plot<-corrplot(corr =Sti.cor,order="AOE",type="upper",tl.col="black",tl.srt = 45,cl.align = "l",tl.pos = "d")
Sti.cor.plot<-corrplot(corr = Sti.cor,add=TRUE, type="lower",method="number",order="AOE", col="black",tl.cex=1.2,diag=FALSE,tl.pos="n", cl.pos="n",p.mat = sig.Sti$p, insig = "label_sig", sig.level = c(.001, .01, .05),pch.cex=1, pch.col = "black",tl.col="black",number.cex = 1.2,tl.srt = 315)
Cle.cor.plot<-corrplot(corr =Cle.cor,order="AOE",type="upper",tl.col="black",tl.srt = 45,cl.align = "l",tl.pos = "d")
Cle.cor.plot<-corrplot(corr = Cle.cor,add=TRUE, type="lower",method="number",order="AOE", col="black",tl.cex=1.2,diag=FALSE,tl.pos="n", cl.pos="n",p.mat = sig.Cle$p, insig = "label_sig",sig.level = c(.001, .01, .05),pch.cex=1,pch.col = "black",tl.col="black",number.cex = 1.2,tl.srt = 315)
Arf.cor.plot<-corrplot(corr =Arf.cor,order="AOE",type="upper",tl.col="black",tl.srt = 45,cl.align = "l",tl.pos = "d")
Arf.cor.plot<-corrplot(corr = Arf.cor,add=TRUE, type="lower",method="number",order="AOE", col="black",tl.cex=1.2,diag=FALSE,tl.pos="n", cl.pos="n",p.mat = sig.Arf$p, insig = "label_sig",sig.level = c(.001, .01, .05),pch.cex=1, pch.col = "black",tl.col="black",number.cex = 1.2,tl.srt = 315)
Com.cor.plot<-corrplot(corr =Com.cor,order="AOE",type="upper",tl.col="black",tl.srt = 45,cl.align = "l",tl.pos = "d")
Com.cor.plot<-corrplot(corr = Com.cor,add=TRUE, type="lower",method="number",order="AOE", col="black",tl.cex=1.2,diag=FALSE,tl.pos="n", cl.pos="n",p.mat = sig.Com$p, insig = "label_sig",sig.level = c(.001, .01, .05),pch.cex=1, pch.col = "black",tl.col="black",number.cex = 1.2,tl.srt = 315)
dev.off()
par(opar)
扫描下方二维码,关注公众号“科学研究进行时”,大家一起交流一起进步哦!