Skip to content

Commit f8d710c

Browse files
committed
figure 2
1 parent b23905a commit f8d710c

File tree

3 files changed

+522
-32
lines changed

3 files changed

+522
-32
lines changed

R/3_dyadicMCMC_groups.R

+45-32
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
# This script follows the super cool approach from Aura Raulo
22
# https://github.com/nuorenarra/Analysing-dyadic-data-with-brms/blob/main/R_Making_dyadic_data/DYADIC_workshop_data_wrangling.Rmd
33

4-
library("MCMCglmm")
5-
library(ape)
64
library(brms)
75
library(rstan)
86
library(RColorBrewer) # needed for some extra colours in one of the graphs
9-
library(ggmcmc)
10-
library(ggthemes)
11-
library(ggridges)
127
library(vegan)
138
library(phyloseq)
149
library(ggplot2)
15-
library(bayesplot)
16-
library(bayestestR)
17-
library(brms)
18-
library(MCMCglmm)
19-
library(doParallel)
20-
library(parallel)
21-
library(magrittr)
22-
library(dplyr)
23-
library(purrr)
24-
library(forcats)
25-
library(tidyr)
26-
library(modelr)
27-
library(ggdist)
28-
library(tidybayes)
29-
library(ggplot2)
3010
library(cowplot)
31-
library(rstan)
32-
library(brms)
33-
library(ggrepel)
34-
library(RColorBrewer)
35-
library(gganimate)
36-
library(posterior)
37-
library(distributional)
3811

3912
### we don't include sex because it does not converge
4013
PS.TSS <- readRDS("tmp/PS.TSS_filtered.rds")
@@ -44,6 +17,13 @@ Parasite <- subset_taxa(PS.TSS, Genus %in%c("Eimeria", "Cryptosporidium", "Sypha
4417
Fungi <- subset_taxa(PS.TSS, Phylum %in% c("Mucoromycota", "Ascomycota", "Basidiomycota"))
4518
Diet <- subset_taxa(PS.TSS, Phylum %in% c("Anthophyta", "Phragmoplastophyta", "Charophyta", "Ochrophyta"))
4619

20+
get_taxa_unique(PS.TSS, "Kingdom")
21+
22+
# How many annotated genera?
23+
Euk <- subset_taxa(PS.TSS, Kingdom %in%"Eukarya")
24+
length(get_taxa_unique(Euk, "Genus"))-length(grep("Unknown", get_taxa_unique(Euk, "Genus")))
25+
length(get_taxa_unique(Bac, "Genus"))-length(grep("Unknown", get_taxa_unique(Bac, "Genus")))
26+
4727
############# First create dyad data#######################
4828
data.dyad <- readRDS("tmp/data.dyad.RDS")
4929

@@ -187,7 +167,7 @@ data.dyad$ait_pla <- ait_pla
187167

188168
#################################
189169
### uploading models
190-
modelA <- readRDS("tmp/BRMmodelA.rds")
170+
FigumodelA <- readRDS("tmp/BRMmodelA.rds")
191171
modelJ <- readRDS("tmp/BRMmodelJac.rds")
192172

193173
modelJ_fun <- readRDS("tmp/BRMmodelJ_fun.rds")
@@ -387,12 +367,12 @@ yearA <- ggplot(res.dfA, aes(x=year_Estimate, y=Domain, colour=Domain))+
387367
theme(legend.position = "none")
388368

389369

390-
Fig2 <- plot_grid(genJ, genA, HeJ, HeA, HxJ, HxA,
370+
Fig2 <- plot_grid(genJ, genA, HeJ, HeA, HxJ, HxA, spaJ, spaA, yearJ, yearA,
391371
labels="auto", ncol=2)
392372

393373
FigS1 <- plot_grid(spaJ, spaA, yearJ, yearA, labels="auto")
394374

395-
ggsave("fig/figure2.pdf", Fig2, width=170, height=180, units="mm", dpi=300)
375+
ggsave("fig/figure2.pdf", Fig2, width=170, height=200, units="mm", dpi=300)
396376

397377
ggsave("fig/figureS1.pdf", FigS1, width=170, height=150, units="mm", dpi=300)
398378

@@ -415,6 +395,14 @@ newdata0.5 <- data.frame(He=seq_range(0:1, n=51),
415395
IDB=rep("AA_0089", 51),
416396
spatial=rep(median(data.dyad$spatial)))
417397

398+
newdata0.63 <- data.frame(He=seq_range(0:1, n=51),
399+
year=rep(0, n=51),
400+
HI=rep(0.63, n=51),
401+
Hx=rep(median(data.dyad$Hx), n=51),
402+
IDA=rep("AA_0197", 51),
403+
IDB=rep("AA_0089", 51),
404+
spatial=rep(median(data.dyad$spatial)))
405+
418406
newdata1 <- data.frame(He=seq_range(0:1, n=51),
419407
year=rep(0, n=51),
420408
HI=rep(0.9, n=51),
@@ -446,6 +434,17 @@ gen5 <-ggplot(pred.df5, aes(x=He, y=.epred))+
446434
ggtitle("Genetic distance = 0.5")+
447435
theme_bw(base_size=10)
448436

437+
pred.df63 <- add_epred_draws(newdata0.63, modelA)
438+
gen63 <-ggplot(pred.df63, aes(x=He, y=.epred))+
439+
stat_lineribbon(size=0.5, .width=c(.95, .8, .5), alpha=0.5) +
440+
# scale_fill_manual(values=microshades_palette("micro_purple"))+
441+
ylab("Gut community similarity")+
442+
xlab("He")+
443+
ylim(-2.04, -1.84)+
444+
labs(fill="level:")+
445+
ggtitle("Genetic distance = 0.63")+
446+
theme_bw(base_size=10)
447+
449448

450449
pred.df1 <- add_epred_draws(newdata1, modelA)
451450
gen1 <-ggplot(pred.df1, aes(x=He, y=.epred))+
@@ -482,6 +481,17 @@ genF5 <-ggplot(predF5, aes(x=He, y=.epred))+
482481
ggtitle("Genetic distance = 0.5")+
483482
theme_bw(base_size=10)
484483

484+
predF63 <- add_epred_draws(newdata0.63, modelA_fun)
485+
genF63 <-ggplot(predF63, aes(x=He, y=.epred))+
486+
stat_lineribbon(size=0.5, .width=c(.95, .8, .5), alpha=0.5) +
487+
# scale_fill_manual(values=microshades_palette("micro_purple"))+
488+
ylim(0.3, 0.55)+
489+
ylab("Gut community similarity")+
490+
xlab("He")+
491+
labs(fill="level:")+
492+
ggtitle("Genetic distance = 0.63")+
493+
theme_bw(base_size=10)
494+
485495

486496
predF1 <- add_epred_draws(newdata1, modelA_fun)
487497
genF1 <-ggplot(predF1, aes(x=He, y=.epred))+
@@ -493,14 +503,17 @@ genF1 <-ggplot(predF1, aes(x=He, y=.epred))+
493503
xlim(min(data.dyad$He[data.dyad$HI>0.9]), max(data.dyad$He[data.dyad$HI>0.9]))+
494504
labs(fill="level:")+
495505
ggtitle("Genetic distance = 0.9")+
496-
theme_bw(base_size=10)
506+
507+
theme_bw(base_size=10)
497508

498509
All <- plot_grid(gen0, gen5, gen1, labels="auto", rel_widths=c(0.7,1,0.7), nrow=1)
499510
Fun <- plot_grid(genF0, genF5, genF1, labels=c("d", "e", "f"), rel_widths=c(0.7,1,0.7), nrow=1)
500511

501512
Fig3 <- plot_grid(All, Fun, ncol=1)
502513

503-
ggplot2::ggsave(file="fig/Fig3.pdf", Fig3, width = 180, height = 170, dpi = 300, units="mm")
514+
ggplot2::ggsave(file="fig/Fig3.pdf", Fig3, width = 185, height = 170, dpi = 300, units="mm")
515+
516+
summary(data.dyad$HI>0.9)
504517

505518
########################Figure 4 ab
506519
# plotting bacteria~fungi

0 commit comments

Comments
 (0)