R-based linkET package qcorrplot visualizes Mantel test correlation network heatmap analysis correlation heatmap

write in front

The requirement is to perform correlation analysis between the differential strains identified in the rumen metagenomic results and the different parts of the apparent indicators, rumen metabolome, serum metabolome, and milk metabolome. The rendering is as follows:

image-20230926151159439

data preparation

Comma separated csv format file, two tables, one is the apparent indicator data corresponding to each sample, the other is the bacterial abundance corresponding to each sample, I use the genus level here

  • Appearance data that needs to be associatedrumen.csv

image-20230926151926227

  • Bacterial abundance in different samplesgenus.csv

image-20230926152040334

R package linkET visualization

  • Packing
install.pakages("linkET")
library(linkET)

If the error is reported that there is a problem with the R version and cannot be installed (this error occurred in my 4.3.1 version of R), please try:

install.packages("devtools")
devtools::install_github("Hy4m/linkET", force = TRUE)
packageVersion("linkET")
  • Read data
library(ggplot2)
rumen <- read.csv("rumen.csv",sep=",",row.name=1,stringsAsFactors = FALSE,check.names = FALSE)
genus <- read.csv("genus.csv",sep=",",row.name=1,stringsAsFactors = FALSE,check.names = FALSE)
#如果报错row.names重复错误请检查数据格式是否为csv
  • rumen.csvintraclass correlation coefficient
matrix_data(list(rumen = rumen)) %>% 
  as_md_tbl()
correlate(rumen) %>% 
  as_matrix_data()
correlate(rumen) %>% 
  as_md_tbl()

correlate(rumen) %>% 
  as_md_tbl() %>% 
  qcorrplot() +
  geom_square()

#如果对“%>%”功能报错,装具有此功能的包即可,比如dplyr

library(vegan)
correlate(rumen, genus, method = "spearman") %>% 
  qcorrplot() +
  geom_square() +
  geom_mark(sep = '\n',size = 3, sig_level = c(0.05, 0.01, 0.001),
            sig_thres = 0.05, color = 'white') + #添加显著性和相关性值
  scale_fill_gradientn(colours = RColorBrewer::brewer.pal(11, "RdBu"))

Insert image description here

  • The two tables are associated to generate a correlation matrix diagram with significance markers.
library(vegan)
correlate(rumen, genus, method = "spearman") %>% 
  qcorrplot() +
  geom_square() +
  geom_mark(sep = '\n',size = 3, sig_level = c(0.05, 0.01, 0.001),
            sig_thres = 0.05, color = 'white') + #添加显著性和相关性值
  scale_fill_gradientn(colours = RColorBrewer::brewer.pal(11, "RdBu"))
image-20230926155801309
  • Processing visualization
library(dplyr)
mantel <- mantel_test(rumen, genus,
                      spec_select = list(Milk_yeild=1,Milk_fat=2,Urea_Nitrogen=3,Butyric_acid=4,Valeric_acid=5,BUN=6,
                                         T_AOC=7,SOD=8,MDA=9,IgA=10,IgG=11))%>% 
  mutate(rd = cut(r, breaks = c(-Inf,  0.5, Inf),
                  labels = c("< 0.5", ">= 0.5")),
         pd = cut(p, breaks = c(-Inf, 0.01, 0.05, Inf),
                  labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))

qcorrplot(correlate(genus), type = "lower", diag = FALSE) +
  geom_square() +geom_mark(sep = '\n',size = 1.8, sig_level = c(0.05, 0.01, 0.001),
    sig_thres = 0.05,color="white") +
  geom_couple(aes(colour = pd, size = rd), 
              data = mantel, 
              curvature = nice_curvature()) +
  scale_fill_gradientn(colours = RColorBrewer::brewer.pal(11, "RdBu")) +
  scale_size_manual(values = c(0.5, 1, 2)) +
  scale_colour_manual(values = color_pal(3)) +
  guides(size = guide_legend(title = "Mantel's r",
                             override.aes = list(color = "black"), 
                             order = 2),
         colour = guide_legend(title = "Mantel's p", 
                               override.aes = list(size = 3), 
                               order = 1),
         fill = guide_colorbar(title = "Pearson's r", order = 3))

Insert image description here

  • The inconspicuous gray connecting lines can also be removed to make the picture cleaner. The rest of the details can be processed by AI.

Guess you like

Origin blog.csdn.net/twocanis/article/details/133313555