1
1
# This script follows the super cool approach from Aura Raulo
2
2
# https://github.com/nuorenarra/Analysing-dyadic-data-with-brms/blob/main/R_Making_dyadic_data/DYADIC_workshop_data_wrangling.Rmd
3
3
4
- library(" MCMCglmm" )
5
- library(ape )
6
4
library(brms )
7
5
library(rstan )
8
6
library(RColorBrewer ) # needed for some extra colours in one of the graphs
9
- library(ggmcmc )
10
- library(ggthemes )
11
- library(ggridges )
12
7
library(vegan )
13
8
library(phyloseq )
14
9
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 )
30
10
library(cowplot )
31
- library(rstan )
32
- library(brms )
33
- library(ggrepel )
34
- library(RColorBrewer )
35
- library(gganimate )
36
- library(posterior )
37
- library(distributional )
38
11
39
12
# ## we don't include sex because it does not converge
40
13
PS.TSS <- readRDS(" tmp/PS.TSS_filtered.rds" )
@@ -44,6 +17,13 @@ Parasite <- subset_taxa(PS.TSS, Genus %in%c("Eimeria", "Cryptosporidium", "Sypha
44
17
Fungi <- subset_taxa(PS.TSS , Phylum %in% c(" Mucoromycota" , " Ascomycota" , " Basidiomycota" ))
45
18
Diet <- subset_taxa(PS.TSS , Phylum %in% c(" Anthophyta" , " Phragmoplastophyta" , " Charophyta" , " Ochrophyta" ))
46
19
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
+
47
27
# ############ First create dyad data#######################
48
28
data.dyad <- readRDS(" tmp/data.dyad.RDS" )
49
29
@@ -187,7 +167,7 @@ data.dyad$ait_pla <- ait_pla
187
167
188
168
# ################################
189
169
# ## uploading models
190
- modelA <- readRDS(" tmp/BRMmodelA.rds" )
170
+ FigumodelA <- readRDS(" tmp/BRMmodelA.rds" )
191
171
modelJ <- readRDS(" tmp/BRMmodelJac.rds" )
192
172
193
173
modelJ_fun <- readRDS(" tmp/BRMmodelJ_fun.rds" )
@@ -387,12 +367,12 @@ yearA <- ggplot(res.dfA, aes(x=year_Estimate, y=Domain, colour=Domain))+
387
367
theme(legend.position = " none" )
388
368
389
369
390
- Fig2 <- plot_grid(genJ , genA , HeJ , HeA , HxJ , HxA ,
370
+ Fig2 <- plot_grid(genJ , genA , HeJ , HeA , HxJ , HxA , spaJ , spaA , yearJ , yearA ,
391
371
labels = " auto" , ncol = 2 )
392
372
393
373
FigS1 <- plot_grid(spaJ , spaA , yearJ , yearA , labels = " auto" )
394
374
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 )
396
376
397
377
ggsave(" fig/figureS1.pdf" , FigS1 , width = 170 , height = 150 , units = " mm" , dpi = 300 )
398
378
@@ -415,6 +395,14 @@ newdata0.5 <- data.frame(He=seq_range(0:1, n=51),
415
395
IDB = rep(" AA_0089" , 51 ),
416
396
spatial = rep(median(data.dyad $ spatial )))
417
397
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
+
418
406
newdata1 <- data.frame (He = seq_range(0 : 1 , n = 51 ),
419
407
year = rep(0 , n = 51 ),
420
408
HI = rep(0.9 , n = 51 ),
@@ -446,6 +434,17 @@ gen5 <-ggplot(pred.df5, aes(x=He, y=.epred))+
446
434
ggtitle(" Genetic distance = 0.5" )+
447
435
theme_bw(base_size = 10 )
448
436
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
+
449
448
450
449
pred.df1 <- add_epred_draws(newdata1 , modelA )
451
450
gen1 <- ggplot(pred.df1 , aes(x = He , y = .epred ))+
@@ -482,6 +481,17 @@ genF5 <-ggplot(predF5, aes(x=He, y=.epred))+
482
481
ggtitle(" Genetic distance = 0.5" )+
483
482
theme_bw(base_size = 10 )
484
483
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
+
485
495
486
496
predF1 <- add_epred_draws(newdata1 , modelA_fun )
487
497
genF1 <- ggplot(predF1 , aes(x = He , y = .epred ))+
@@ -493,14 +503,17 @@ genF1 <-ggplot(predF1, aes(x=He, y=.epred))+
493
503
xlim(min(data.dyad $ He [data.dyad $ HI > 0.9 ]), max(data.dyad $ He [data.dyad $ HI > 0.9 ]))+
494
504
labs(fill = " level:" )+
495
505
ggtitle(" Genetic distance = 0.9" )+
496
- theme_bw(base_size = 10 )
506
+
507
+ theme_bw(base_size = 10 )
497
508
498
509
All <- plot_grid(gen0 , gen5 , gen1 , labels = " auto" , rel_widths = c(0.7 ,1 ,0.7 ), nrow = 1 )
499
510
Fun <- plot_grid(genF0 , genF5 , genF1 , labels = c(" d" , " e" , " f" ), rel_widths = c(0.7 ,1 ,0.7 ), nrow = 1 )
500
511
501
512
Fig3 <- plot_grid(All , Fun , ncol = 1 )
502
513
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 )
504
517
505
518
# #######################Figure 4 ab
506
519
# plotting bacteria~fungi
0 commit comments