今天小雲想學習利用linkET包來繪制mantel test相關性熱圖,代碼如下:
01
安裝需要的R包
install.packages(“ggplot2”)install.packages(“tidyverse”)install.packages(“devtools”)devtools::install_github("Hy4m/linkET", force = TRUE)
02
載入需要的R包
library(devtools)library(ggplot2)library(tidyverse)library(linkET)
03
代碼展示
#讀取數據varechem<-read.csv(file="varechem.csv",row.names=1)
varespec<-read.csv(file="varespec.csv",row.names=1)
b228284c8c6807dac506eab34e7d96da
# mantel testmantel <- mantel_test(varespec, varechem, # 傳入需要檢測的兩個矩陣 mantel_fun = 'mantel', spec_select = list(Spec01 = 1:7, Spec02 = 8:18, Spec03 = 19:37, Spec04 = 38:44)) %>% mutate(r = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf), labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")), p = cut(p, breaks = c(-Inf, 0.01, 0.05, Inf), labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))#計算環境因子相關性系數:cor2 <- correlate(varechem)
#繪制相關性熱圖p1<- qcorrplot(cor2,grid_col = "grey50",grid_size = 0.2,type = "upper",diag = FALSE) +geom_square() +scale_fill_gradientn(colours = c("#610214", "#d05646", "#f5f4f4", "#569cc7", "#0b3b71"),limits = c(-1, 1))
#添加顯著性標簽:p2 <- p1+geom_mark(size = 4,only_mark = T,sig_level = c(0.05, 0.01, 0.001),sig_thres = 0.05,colour = 'white')
#在相關性熱圖上添加mantel連線:p3<- p2+geom_couple(data = mantel,aes(colour = p, size = r),curvature = nice_curvature())+scale_size_manual(values = c(0.5, 1.2, 2)) + #連線粗細scale_colour_manual(values = c("#d85c01", "#29d300", "#A2A2A288")) + #連線配色#修改圖例:guides(size = guide_legend(title = "Mantel r",override.aes = list(colour = "grey35"),order = 2),colour = guide_legend(title = "Mantel p",override.aes = list(size = 3),order = 1),fill = guide_colorbar(title = "Pearson r", order = 3))
d64555bae25c8f83fa169f08532079a4
小雲感覺效果還不錯,該包與ggplot2語法兼容,在繪圖的同時可以學習相關的ggplot2的繪圖知識,值得推薦,今天小雲的分享就到這裡瞭,有需要的可以借鑒學習,下期再見。
選分析方向可以從最新發表文獻入手,當然最便捷的方法當然還是持續關註小雲的生信思路推薦,想定制創新性思路歡迎直接call小雲,雲生信團隊竭誠為您的科研助力!
上一篇
下一篇