#FIG1 getwd() setwd("D:/R work") rm(list = ls()) #install.packages("readxl") #install.packages("pheatmap") library(readxl) library(pheatmap) library(psych) library(reshape2) microbiota <- data.frame(read_excel("microbiota.xlsx"),stringsAsFactors = FALSE) rownames(microbiota) =microbiota$sample microbiota = microbiota[,-1] inflammatory <- data.frame(read_excel("inflammatory.xlsx"),stringsAsFactors = FALSE) rownames(inflammatory) = inflammatory$sample inflammatory = inflammatory[,-1] View(microbiota) head(inflammatory) cor <- corr.test(microbiota,inflammatory,method="spearman",adjust = "fdr") cmt <- cor$r pmt <- cor$p cmt.out<-cbind(rownames(cmt),cmt) pmt.out<-cbind(rownames(pmt),pmt) df <- melt(cmt,value.name="cor") df$pvalue <- as.vector(pmt) head(df) View(cmt) if (!is.null(pmt)) { ssmt <- pmt < 0.01 pmt[ssmt] <- '**' smt <- pmt > 0.01& pmt <0.05 pmt[smt] <- '*' pmt[!ssmt&!smt] <- '' } else { pmt <- F } pheatmap(cmt, scale = "none", cluster_row = T, cluster_col = F, display_numbers = pmt, fontsize_number = 12, number_color = "white", cellwidth = 20, cellheight = 20) pheatmap(cmt, scale = "none", cluster_row = T, cluster_col = F, display_numbers = T, fontsize_number = 12, number_color = "white", cellwidth = 20, cellheight = 20) #FIG2 getwd() setwd("D:/R work") rm(list = ls()) #install.packages("readxl") #install.packages("pheatmap") library(readxl) library(pheatmap) library(psych) library(reshape2) microbiota <- data.frame(read_excel("microbiota.xlsx"),stringsAsFactors = FALSE) rownames(microbiota) =microbiota$sample microbiota = microbiota[,-1] cognitive <- data.frame(read_excel("cognitive.xlsx"),stringsAsFactors = FALSE) rownames(cognitive) = cognitive$sample cognitive = cognitive[,-1] View(microbiota) head(cognitive) cor <- corr.test(microbiota,cognitive,method="spearman",adjust = "fdr") cmt <- cor$r pmt <- cor$p cmt.out<-cbind(rownames(cmt),cmt) pmt.out<-cbind(rownames(pmt),pmt) df <- melt(cmt,value.name="cor") df$pvalue <- as.vector(pmt) head(df) View(cmt) if (!is.null(pmt)) { ssmt <- pmt < 0.01 pmt[ssmt] <- '**' smt <- pmt > 0.01& pmt <0.05 pmt[smt] <- '*' pmt[!ssmt&!smt] <- '' } else { pmt <- F } pheatmap(cmt, scale = "none", cluster_row = T, cluster_col = F, display_numbers = pmt, fontsize_number = 12, number_color = "white", cellwidth = 20, cellheight = 20) pheatmap(cmt, scale = "none", cluster_row = T, cluster_col = F, display_numbers = T, fontsize_number = 12, number_color = "white", cellwidth = 20, cellheight = 20)