R可视化:mantel_test结果可视化
2024-07-10 本文已影响0人
生信学习者2
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))
![](https://img.haomeiwen.com/i10780526/8442dd49aa7e7b3e.png)