-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvenn_diagram.R
47 lines (35 loc) · 1.06 KB
/
venn_diagram.R
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
#### Setup ####
source("scripts/00_helperfunctions/alx_OutOfSight.R")
inputfolder <- "../data/processed"
figfolder <- "../results/output_figures/bacteria"
dir.create(figfolder, showWarnings = FALSE)
if ( !require("phyloseq", quietly = TRUE) )
BiocManager::install("phyloseq")
if ( !require("microbiome", quietly = TRUE) )
BiocManager::install("microbiome")
if ( !require("VennDiagram", quietly = TRUE) )
BiocManager::install("VennDiagram")
#### Read data ####
bacter <- readRDS(
paste0(inputfolder,
"/bacter_rar_genus.rds")
)
# Extract OTU
otu_table <- otu_table(bacter) %>% data.frame
# Metadata
meta <- sample_data(bacter) %>% data.frame
# OTUs per Country
otu_list <- lapply(split(otu_table, meta$Country), function(df) rownames(df))
#### Venn diagram ####
venn_diagram <- venn.diagram(
x = otu_list,
category.names = names(otu_list),
filename = NULL,
output = TRUE
)
grid.draw(venn_diagram)
# Save plot
png(filename = paste0(figfolder, "/venn_diagram_bacteria_genus.png"),
width = 800, height = 800)
grid.draw(venn_diagram)
dev.off()