美文网首页
R可视化:mantel_test结果可视化

R可视化:mantel_test结果可视化

作者: 生信学习者2 | 来源:发表于2024-07-10 10:20 被阅读0次
library(tidyverse)
library(linkET)

data("varechem", package = "vegan")
data("varespec", package = "vegan")

mantel <- linkET::mantel_test(
    spec = varespec, 
    env = varechem, 
    spec_select = list(Spec01 = 1:7,
                       Spec02 = 8:18,
                       Spec03 = 19:37,
                       Spec04 = 38:44)) %>% 
  mutate(rd = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf),
                  labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")),
         pd = cut(p, breaks = c(-Inf, 0.01, 0.05, Inf),
                  labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))
#> `mantel_test()` using 'bray' dist method for 'spec'.
#> `mantel_test()` using 'euclidean' dist method for 'env'.

qcorrplot(linkET::correlate(varechem), type = "lower", diag = FALSE) +
  geom_square() +
  geom_couple(data = mantel, 
              aes(colour = pd, size = rd), 
              curvature = nice_curvature()) +
  scale_fill_gradientn(colors = 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 = "grey35"), 
                             order = 2),
         color = guide_legend(title = "Mantel's p", 
                              override.aes = list(size = 3), 
                              order = 1),
         fill = guide_colorbar(title = "Pearson's r", order = 3))

相关文章

网友评论

      本文标题:R可视化:mantel_test结果可视化

      本文链接:https://www.haomeiwen.com/subject/xbzzcjtx.html