-
Notifications
You must be signed in to change notification settings - Fork 0
/
manteltest.txt
59 lines (51 loc) · 2.36 KB
/
manteltest.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#Welcome to ENDO!!!
#This is a script about mantel test
#You may link gene expression or gut microbiota with other measured parameters by using this
library(tidyverse)
library(ggcor)
library(vegan)
rm(list=ls())#clear Global Environment
setwd('D:\\manteltest')
df <- read.table("otu.txt",sep="\t",header = T,row.names = 1,check.names = F)
env <- read.table("lipid.txt",sep="\t",header = T,row.names = 1,check.names = F)
mantel <- mantel_test(df, lipid, # Enter the two matrices that need to be detected
# Microbiota can be divided into several categories
spec.select = list(Cat_1 = 1:5,
Cat_2 = 6:10
)) %>%
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.value, breaks = c(-Inf, 0.01, 0.05, Inf),
labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))
quickcor(env, type = "lower") +
geom_square() +
# The data here is passed into the mantel test result: the color of the block changes according to PD, and the size changes according to RD;
anno_link(aes(colour = pd, size = rd), data = mantel) +
scale_size_manual(values = c(0.5, 1, 2))+
guides(size = guide_legend(title = "Mantel's r",
order = 2),
colour = guide_legend(title = "Mantel's p",
order = 1),
fill = guide_colorbar(title = "Pearson's r", order = 3))
#or if you want to make this graph more cute
library(ggplot2)
library(ggnewscale)
# set up a beautiful theme
my_theme <- theme_minimal()
# Modify the color scheme by using predefined palettes or custom colors
my_palette <- c("blue", "green", "red")
# Modify labels and titles
x_label <- "Lipid levels"
y_label <- "Microbiota similarity"
# Plot!
plot <- quickcor(env, type = "lower") +
geom_square() +
anno_link(aes(colour = pd, size = rd), data = mantel) +
scale_size_manual(values = c(0.5, 1, 2)) +
guides(size = guide_legend(title = "Mantel's r", order = 2),
colour = guide_legend(title = "Mantel's p", order = 1),
fill = guide_colorbar(title = "Pearson's r", order = 3)) +
scale_color_manual(values = my_palette) +
labs(x = x_label, y = y_label) +
my_theme
plot