Data input

library(readxl)
otu_top100 <- read_excel("D:/(R) plots for laoma/Zhenhe/figures/zhenhe_network_gephi/otu_table_5,12,17,29_top100-0507.xlsx")
## New names:
## * `` -> ...1
data = data.frame(otu_top100)
rownames(data) = data[,1]
data = data[,-1]
data = t(data)
data[, 1:5] #查看部分数据
##      OTU805 OTU646 OTU160 OTU151 OTU472
## MJ5     126    392      0      0     11
## MJ12      0     77      0  11984  11814
## MJ17    236   1293  13520     28     14
## MJ29  32281  18152     96      1     27

Generate correlation matrix

library(psych)
occor = corr.test(data,use="pairwise",method="spearman",adjust="fdr",alpha=0.05)
occor.r = occor$r # 取相关性矩阵R值
occor.p = occor$p # 取相关性矩阵p值
# occor.r[occor.p>0.01|abs(occor.r)<0.6] = 0 
occor.r[1:5, 1:5] #查看部分数据
##            OTU805     OTU646     OTU160     OTU151     OTU472
## OTU805  1.0000000  1.0000000  0.7378648 -0.4000000 -0.2000000
## OTU646  1.0000000  1.0000000  0.7378648 -0.4000000 -0.2000000
## OTU160  0.7378648  0.7378648  1.0000000  0.1054093 -0.1054093
## OTU151 -0.4000000 -0.4000000  0.1054093  1.0000000  0.8000000
## OTU472 -0.2000000 -0.2000000 -0.1054093  0.8000000  1.0000000
dat = occor.r[1:30, 1:30]

Set color

library(paletteer)
library(RColorBrewer)
my_color = rev(paletteer_d("RColorBrewer::RdYlGn"))
my_color = colorRampPalette(my_color)(10)

Plot!

library(corrplot)
## corrplot 0.87 loaded
corrplot(dat, 
         method="pie",
         order="hclust", 
         col=my_color,
         tl.col=NULL, 
         #tl.pos = "d",
         tl.srt=45, tl.cex = 0.4, addgrid.col = 'white', outline = 'white') 

Just the upper

library(corrplot)
corrplot(dat, method="pie", type = 'upper', order="hclust", col=my_color,
  tl.col=NULL, #tl.pos = "d", 
  tl.srt=45, tl.cex = 0.4, addgrid.col = 'white', outline = 'white') 

Just the lower

corrplot(dat, 
         method="pie", type = 'lower',
         order="hclust", 
         col=my_color,
         tl.col=NULL, 
         #tl.pos = "d",
         tl.srt=45, tl.cex = 0.4, addgrid.col = 'white', outline = 'white') 

Change color and shape!

corrplot(dat, 
         method="circle",
         order="hclust", 
         col=my_color,
         tl.col=NULL, 
         #tl.pos = "d",
         tl.srt=45, tl.cex = 0.4, addgrid.col = 'white', outline = 'white') 

my_color = rev(paletteer_d("RColorBrewer::RdYlBu"))
my_color = colorRampPalette(my_color)(10)
corrplot(dat, 
         method="pie",
         order="hclust", 
         col=my_color,
         tl.col=NULL, 
         #tl.pos = "d",
         tl.srt=45, tl.cex = 0.4, addgrid.col = 'white', outline = 'white')