-
Notifications
You must be signed in to change notification settings - Fork 0
/
T18.Dataanalysis.Rmd
1961 lines (1632 loc) · 94.3 KB
/
T18.Dataanalysis.Rmd
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Topf2018.Dataanalysis_FINALforPUBLI"
author: "Lukas Wille"
date: "`r format(Sys.Date(), '%d/%m/%y')`"
output:
pdf_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r Libraries I need, echo=FALSE, message=FALSE, error=FALSE}
library(dplyr)
library(tidyr)
library(purrr)
library(reshape2)
library(ggplot2)
library(ggpmisc)
library(gridExtra) # fuer grid.arrange
library(LambertW)
library(emmeans)
library(ARTool) # For Aligned Rans transformation ANOVA of Root Rot index
library(vegan)
library(ecoCopula) # Graphical model (Gordana Popovic)
library(ordinal) # for ecoCopula
library(mvabund) # analysis of multivariate abundance data
library(labdsv) # Ordination analysis in community ecology for ecoCopula analysis
library(igraph)
library(mgcv)
#library(SpiecEasi)
```
```{r WD setup, echo=FALSE, error=TRUE}
setwd("~/ownCloud/FiblWulche/Dataanalysis/Topfversuch2018/FinalAnalysisforPubli") # MAC
#setwd("C:/Users/lukas.wille/ownCloud/FiblWulche/Dataanalysis/Topfversuch2018/FinalAnalysisforPubli") # WIN
```
```{r Read-in ready Data, echo=FALSE, warning=FALSE, error=TRUE}
setwd("~/ownCloud/FiblWulche/Dataanalysis/Topfversuch2018/DataframeszumSchaffe") # MAC
#setwd("C:/Users/lukas.wille/ownCloud/FiblWulche/Dataanalysis/Topfversuch2018/DataframeszumSchaffe") # WIN
# Phenotypic data
Topf18.S <- readRDS("Topf18.S.rds")
Topf18.NS <- readRDS("Topf18.NS.rds")
Topf18.4.8 <- readRDS("Topf18.4.8.rds") # only 4 soils, 8 Acc's, S and NS
Topf18.4.8.S <- readRDS("Topf18.4.8.S.rds")
Topf18.4.8.NS <- readRDS("Topf18.4.8.NS.rds")
Topf18.4.8.3sick <- readRDS("Topf18.4.8.3sick.rds")
# qPCR data for 10 fungis
Topf18.FUNGI <- readRDS("Topf18.FUNGI.rds") # DFs with only qPCR Conc Data (ONE & TWO are the 2 tech reps.; Fungal name without suffix ONE/TWO ist the mean between the two...)
Topf18.FUNGI.3SICK <- readRDS("Topf18.FUNGI.3SICK.rds")
Topf18.FUNGI.S <- readRDS("Topf18.FUNGI.S.rds")
```
```{r helper vectors, echo=FALSE}
thefungis <- names(Topf18.FUNGI)[c(9,12,15,18,21,24,27,30,33,36)] # Taxa names of the fungis
thefungis <- set_names(thefungis) #Purrr Package for set_names function
theaccs <- set_names(levels(Topf18.NS$acc))
soil_names <- c(`F` = "Feldbach",`H` = "Kirchlindach",`L` = "Puch",`W` = "Neu-Eichenberg") # note: the original factor level coding (used for the analysis) of the 4 soils is "F", "H", "L" and "W". For the presentation of the results "F(eldbach)", "K(irchlindach)", "P(uch)" and N(eu-Eichenberg)" is used...
soil_nms <- c(`F` = "F",`H` = "K",`L` = "P",`W` = "N")
Kolor = c("#009900","#FF0033","#CC9900","#663333") # colors for the 4 soils
fungKolor = c("#A1D99B", "#800026", "darkgreen", "#FC9272", "#3399FF", "#C994C7", "#E6550D", "black", "#FED976", "pink")
```
# Analysis of shoot dry weight (SDW) - S vs NS treatment --> FIGURE S1
I use this analysis to show that the 3 sick soils are sick, and Feldbach healthy. This gives a Supplementary figure.
https://authorservices.wiley.com/asset/photos/electronic_artwork_guidelines.pdf
https://nph.onlinelibrary.wiley.com/hub/journal/14698137/about/author-guidelines
```{r Fig S1, echo=FALSE, warning=FALSE}
plotSDW <- ggplot(aes(treat, s.dw.1), data=Topf18.4.8) +
geom_boxplot() +
stat_summary(fun.y=mean, geom="point", shape=4, size=4) +
facet_wrap(~soil, labeller = labeller(soil = soil_names)) +
theme_bw() +
theme(legend.title = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank()) +
labs(y=expression("Shoot dry weight [g]"),
x=expression("Soil treatment")) +
ggpubr::stat_compare_means(method = "t.test", label.y = 0.6) # to directly plot p-values of t.test into plot :) For New Phyt I should give the df's as well, however, I do not see that in all the published papers...
plotSDW
#ggsave("SDW_SvsNS_in4soils.eps", plotSDW, units="cm", width=18, height=10, dpi=600, device = "eps") # I save only once. 80mm width is one col in New Phytologist; 180mm is two cols
#ggsave("SDW_SvsNS_in4soils.png", plotSDW, units="cm", width=18, height=10, dpi=200) #png
#ggsave("SDW_SvsNS_in4soils.jpg", plotSDW, units="cm", width=18, height=10, dpi=200) #jpg
```
\newpage
# Analysis of relative shoot dry weight (SDWRel)
## Summarize SDWrel (N, mean +- SD)
```{r summary pheno for soils and accs, echo=FALSE, message=FALSE}
sumbysoilacc_SDWrel <- Topf18.4.8.NS %>% group_by(soil, acc) %>%
summarise(N_not_NA = sum(!is.na(s.dw.ratioSNS)),
mean= mean(s.dw.ratioSNS, na.rm = TRUE),
sd = sd(s.dw.ratioSNS, na.rm = TRUE))
sumbysoilacc_SDWrel
```
-> C2 in F and W has two observations (all others have 3 at least). I leave C2 in for the analysis of SDWRel.
## Regression/ANOVA of SDWrel with factor 'acc'
-> Original SDWRel data is Lambert W x Fx transformed ("Gaussianized", Goerg 2015)
```{r Gaussianize SDWRel, echo=FALSE, message=FALSE}
# reduce dataset to variable in focus and design variables
Topf18.4.8.NS.SDWRel.GAUSS <- Topf18.4.8.NS[,c(1:10,27)]
p <- Topf18.4.8.NS.SDWRel.GAUSS[,c(2,11)] # only LABEL and SDWrel
p <- p[complete.cases(p), ] # the Gaussianize function does not work with NAs; so I take them out, and put them back after the whole procedure
# do the transformation
G_List_SDWRel <- LambertW::Gaussianize(p[,2], type="hh", method = "MLE", return.tau.mat = TRUE)
p$SDWRel_G<-as.vector(G_List_SDWRel$input)
Topf18.4.8.NS.SDWRel.GAUSS <- merge(Topf18.4.8.NS.SDWRel.GAUSS, p[c("LABEL", "SDWRel_G")], all.x=TRUE)
# Remove objects
rm(p)
```
After transformation I do the linear Model:
```{r formulate the Model and get Anova 4 soils acc, echo=FALSE, message=FALSE}
LM.48.SDW_G <- lm(SDWRel_G ~ soil * acc + rep, Topf18.4.8.NS.SDWRel.GAUSS,
contrasts=list(soil=contr.sum, acc=contr.sum, rep=contr.sum)) # the "contrasts" statement needs to be set like this for proper calculation of Anova type III
car::Anova(LM.48.SDW_G, type="III")
#Model diagnostic via residuals
par(mfrow=c(1,2))
scatter.smooth(fitted(LM.48.SDW_G), resid(LM.48.SDW_G)); abline(h=0,lty=2)
title("Tukey-Anscombe Plot")
car::qqPlot(resid(LM.48.SDW_G), pch=3, cex=0.5, id=list(n=5, cex=0.7, col="red"), line="quartiles")
```
Result: soil & acc are signf.; interaction not. Residuals look ok.
## Post-hoc analysis: Planned contrasts between resistant and susceptible genotypes for each soil
```{r posthoc SDW orthogonal reslevel within soil, echo=FALSE, message=FALSE}
emm.LM.SoilxAcc.SDW_G <- emmeans(LM.48.SDW_G, c("acc", "soil"))
levels(Topf18.4.8.NS.SDWRel.GAUSS$acc) # check the order of the accs: "C1" "C2" "G78" "G89" "S134" "S22" "S64" "S91" -> in order to specify the dummy variables for the contrasts correctly
Contrasts = list(Res_vs_susceptible = c(1/5, -1/3, 1/5, -1/3, 1/5, -1/3, 1/5, 1/5)) # I need to specify the contrasts so that the 5 resistant and the 3 susceptible genotypes sum-up to 0.
contrast(emm.LM.SoilxAcc.SDW_G, Contrasts, by="soil")
```
I see that R-S do not significantly differ in F. But S are significantly lower than R in the three infested soils.
## Regression/ANOVA of SDWrel with factor 'reslevel'
-> to test differences between the two groups resistant and susceptible a new model is fit where the factor 'acc' is replaced by 'reslevel'
```{r formulate the Model and get Anova 4 soils resistance, echo=FALSE, message=FALSE}
LM.48.SDW_G_reslevel <- lm(SDWRel_G ~ soil * reslevel + rep, Topf18.4.8.NS.SDWRel.GAUSS,
contrasts=list(soil=contr.sum, reslevel=contr.sum, rep=contr.sum)) # the "contrasts" statement needs to be set like this for proper calculation of Anova type III
car::Anova(LM.48.SDW_G_reslevel, type="III")
#Model diagnostic via residuals
par(mfrow=c(1,2))
scatter.smooth(fitted(LM.48.SDW_G_reslevel), resid(LM.48.SDW_G_reslevel)); abline(h=0,lty=2)
title("Tukey-Anscombe Plot")
car::qqPlot(resid(LM.48.SDW_G_reslevel), pch=3, cex=0.5, id=list(n=5, cex=0.7, col="red"), line="quartiles")
```
-> soil, reslevel & interaction are significant. Residuals look ok.
I do not show this result in the publication. However, the post-hoc analysis of reslevel within each soil is interesting:
```{r reslevel 4 soils post-hoc, echo=FALSE, message=FALSE}
emm.LM.SoilxAcc.SDW_G_reslevel <- emmeans(LM.48.SDW_G_reslevel, c("soil", "reslevel"))
POSTHOC_SDW_G_TukeySoilxAcc_reslevel <- contrast(emm.LM.SoilxAcc.SDW_G_reslevel, method="pairwise", by="soil")
POSTHOC_SDW_G_TukeySoilxAcc_reslevel
```
## Regression/ANOVA of SDWrel only in the 3 infested soils with factor 'acc
```{r formulate the Model and get Anova 3 soils acc, echo=FALSE, message=FALSE}
LM.48.SDW_G_3sick <- lm(SDWRel_G ~ soil * acc + rep, Topf18.4.8.NS.SDWRel.GAUSS[Topf18.4.8.NS.SDWRel.GAUSS$soil!="F",],
contrasts=list(soil=contr.sum, acc=contr.sum, rep=contr.sum)) # the "contrasts" statement needs to be set like this for proper calculation of Anova type III
car::Anova(LM.48.SDW_G_3sick, type="III")
#Model diagnostic via residuals
par(mfrow=c(1,2))
scatter.smooth(fitted(LM.48.SDW_G_3sick), resid(LM.48.SDW_G_3sick)); abline(h=0,lty=2)
title("Tukey-Anscombe Plot")
car::qqPlot(resid(LM.48.SDW_G_3sick), pch=3, cex=0.5, id=list(n=5, cex=0.7, col="red"), line="quartiles")
```
In order to compare the genotypic means in the 3 sick soils post-hoc analysis (Tukeys HSD) are done. Because there is no significant soil x acc interaction, estimated means are calculated for each genotype over the 3 sick soils (note the warning of the emmeans() function)
```{r post hoc analysis 3 sick soils acc, echo=FALSE, message=FALSE}
#contrast(emmeans(LM.48.SDW_G_3sick, ~ acc), method="pairwise")
(ph <- as.data.frame(multcomp::cld(emmeans(LM.48.SDW_G_3sick, "acc"), alpha=0.05, Letters=letters, decreasing = TRUE, adjust="tukey"))) # letter display for the pairwise testing - I save this df for use in the plot futher up
```
## Plot SDWrel: 4 soils over 8 genotypes & 4 soils-8 genotypes individually: Mean +- SE --> FIGURE 1
```{r beautiful SDWRel plot, echo=FALSE, message=FALSE}
#Panel A: The boxplot of the 4 soils
gh <- ggplot() +
geom_boxplot(data = Topf18.4.8.NS, aes(x = soil, y = s.dw.ratioSNS, fill = soil), outlier.size = 0.5) +
stat_summary(data = Topf18.4.8.NS, aes(x = soil, y = s.dw.ratioSNS), fun=mean, geom="point", shape=4, size=2) +
scale_fill_manual(values = Kolor, labels = soil_names) +
theme_classic() +
scale_y_continuous(sec.axis = dup_axis(breaks = 0), # put a fake right y-axis as border...
expand = c(0, 0),
breaks = c(0,1,2)) +
coord_cartesian(ylim = c(-0.13, 2.5)) + # set explicit range
geom_hline(yintercept = 2.5) +
geom_hline(yintercept = 1, lty = 2, size = 0.5) +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_text(size=8),
axis.title.y.right = element_blank(), # hide right axis title
axis.text.y.right = element_blank(),
axis.ticks.y.right = element_blank(),
axis.title.y.left = element_text(size=8),
legend.title = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank()) +
labs(tag="(a)",
y=expression(SDW[italic(Rel.)]),
x=expression("Soil")) +
annotate("text", x = 1, y = 1.8, label = "a", size=3) +
annotate("text", x = 2, y = 1.6, label = "bc", size=3) +
annotate("text", x = 3, y = 1.5, label = "c", size=3) +
annotate("text", x = 4, y = 1.7, label = "b", size=3) +
guides(fill = guide_legend(ncol = 2))
# Panel B: The kindofainteractionplot showing the genotypes -> this plot also generates the legend for both panels
sum <- sumbysoilacc_SDWrel
sum <- sum %>% mutate(se=sd/sqrt(N_not_NA)) #add SE to the sum file
sum$acc <- factor(sum$acc, c("resistant", "S91", "S134", "G78", "C1", "S64", "susceptible", "G89", "S22", "C2", "", " ")) # #the empty "fake" factors are placeholders for the legendfrom 18.1.21 on
# do the plot!
gc <- ggplot(data = sum) +
geom_linerange(aes(x = acc, ymin = mean - se, ymax = mean + se, color = soil)) +
geom_point(aes(x = acc, y = mean, shape = acc, color = soil), size=1.5) +
facet_wrap(~soil, nrow = 1, labeller = labeller(soil = soil_names)) +
scale_shape_manual(values = c(NA, 19, 15, 18, 17, 20, NA, 2, 1, 0, NA, NA), drop=FALSE) + # !
scale_color_manual(values = Kolor, labels = soil_names) +
scale_fill_manual(labels = soil_names) +
theme_classic() +
scale_y_continuous(labels = function(x){paste(x, "-")},
sec.axis = dup_axis(breaks = 0),
expand = c(0, 0),
breaks = c(0,1,2)) + # put a fake right y-axis as border...
coord_cartesian(ylim = c(-0.13, 2.5)) + # set explicit range
geom_hline(yintercept = 2.5 ) +
geom_hline(yintercept = 1, lty = 2, size = 0.5) +
theme(
axis.text.x = element_blank(),
axis.title.x = element_text(size=8),
axis.ticks.x = element_blank(),
axis.title.y.right = element_blank(), # hide right axis title
axis.text.y = element_blank(),
axis.ticks.y.right = element_blank(),
panel.spacing = unit(0, "lines"),
panel.background = element_blank(),
panel.grid = element_blank(),
strip.background = element_blank(),
strip.text.x = element_blank(),
legend.title = element_blank(),
legend.spacing.y = unit(0, "cm"),
legend.spacing.x = unit(-0.15, "cm"),
legend.key.size = unit(1.2, 'lines'),
legend.text = element_text(size=6),
legend.margin = margin(0, 0, 0, 0)
) +
labs(tag="(b)",
y=expression(""),
x=expression("Genotype")) +
geom_text(data=data.frame(soil="F"), color=Kolor[1], label=expression(paste(italic(P[R-S]), " = .68")), x=4.5, y=0, size=2, parse = TRUE) +
geom_text(data=data.frame(soil="H"), color=Kolor[2], label=expression(paste(italic(P[R-S]), " < .001")), x=4.5, y=0, size=2, parse = TRUE) +
geom_text(data=data.frame(soil="L"), color=Kolor[3], label=expression(paste(italic(P[R-S]), " = .01")), x=4.5, y=0, size=2) +
geom_text(data=data.frame(soil="W"), color=Kolor[4], label=expression(paste(italic(P[R-S]), " = .006")), x=4.5, y=0, size=2) +
guides(shape = guide_legend(ncol = 2, override.aes = list(shape = c(NA, 19, 15, 18, 17, 20, NA, 2, 1, 0, NA, NA))),
color = guide_legend(ncol = 2, override.aes = list(linetype = c(0,0))))
# add post-hoc table
#prepare the post-hoc table with the genotypic means
phtable <- ph[,c(1,2,7)] # this "ph" df is produced in the post-hoc analysis after ANOVA (code line 427; I know, this is stupid coding...) of the three sick soils. it contains emmeans, but I want means:
sumSDWacc <- Topf18.4.8.3sick %>% group_by(acc) %>% summarise(meanSDW = mean(s.dw.ratioSNS, na.rm=TRUE))
sumSDWacc$meanSDW <- round(sumSDWacc$meanSDW, 2)
phtable <- inner_join(phtable[,c(1,3)], sumSDWacc, by="acc") # replace emmenas by means
phtable <- phtable[,c(1,3,2)]
colnames(phtable)[3] <- "group"
phtable$group <- c(" d", " cd", " bcd", "abc ", "abc ", "ab ", "a ", "a ") # I can't believe that I am doing this :)
phtable <- phtable[order(phtable$meanSDW, decreasing = TRUE),]
# little function "annotation2"
annotation_custom2 <- function (grob, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, data) {
layer(data = data, stat = StatIdentity, position = PositionIdentity,
geom = ggplot2:::GeomCustomAnn,
inherit.aes = TRUE, params = list(grob = grob,
xmin = xmin, xmax = xmax,
ymin = ymin, ymax = ymax))
}
tg <- tableGrob(phtable, rows=NULL, cols=NULL, theme = ttheme_minimal(base_size=6, padding = unit(c(1,1), "mm")), )
gcplus <- gc + annotation_custom2(tg, data=data.frame(soil="L"), xmin = 1, xmax = 8, ymin = 1.3, ymax = 2.3)
#put the two panels A + B & Save
props <- ggpubr::ggarrange(gh + theme(legend.position="none"),
gcplus,
widths = c(1,4,3),
nrow=1)
props
#ggsave("SDWrelBoxplotwithInteractionplo.eps", props, units="cm", width=18, height=6, dpi=600) # I save only once.
#ggsave("SDWrelBoxplotwithInteractionplo.png", props, units="cm", width=18, height=6, dpi=200) #png
```
### Plot RRI, again for soils and for accs in soils --> FIGURE S2
.
```{r suppFig RRI, echo=FALSE, message=FALSE, warning=FALSE}
# Panel A: The boxplot of the 4 soils
rh <- ggplot(data = Topf18.4.8.NS, aes(x = soil, y = r.aspectMEDIAN, color = soil, fill = soil)) +
geom_violin(alpha = 0.3) + # for the RRI I make a Violinplot as there is no IQR an dboxplot does not make sense
geom_jitter(width = 0.25, size=1) +
scale_fill_manual(values = Kolor) +
scale_color_manual(values = Kolor) +
theme_classic() +
scale_y_continuous(sec.axis = dup_axis(breaks = 0), # put a fake right y-axis as a panel border...
expand = c(0, 0),
breaks = c(0,1,2,3,4,5)) +
coord_cartesian(ylim = c(0, 6)) + # set explicit range of the y axis (aka the left and right border)
geom_hline(yintercept = 6) +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y.right = element_blank(), # hide right axis title
axis.text.y.right = element_blank(),
axis.ticks.y.right = element_blank(),
legend.position = "none", # this panel has no legend, as it will use the one from the panel B
legend.title = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank()) +
labs(tag="(a)",
y=expression(RRI),
x=expression("Soil")) +
annotate("text", x = 1, y = 0.5, label = "a") + # put some significance letters
annotate("text", x = 2, y = 1.1, label = "bc") +
annotate("text", x = 3, y = 1.2, label = "c") +
annotate("text", x = 4, y = 1, label = "b")
# Panel B: The kindofainteractionplot showing the genotypes -> this plot generates the legend for both panels
sumbysoilacc_RRI <- Topf18.4.8.NS %>% group_by(soil, acc) %>%
summarise(N_not_NA = sum(!is.na(r.aspectMEAN)),
mean= mean(r.aspectMEAN, na.rm = TRUE),
sd = sd(r.aspectMEAN, na.rm = TRUE))
sumr <- sumbysoilacc_RRI
sumr <- sumr %>% mutate(se=sd/sqrt(N_not_NA)) # add SE to the sum file
sumr$acc <- factor(sumr$acc, c("resistant", "S91", "S134", "G78", "C1", "S64", "susceptible", "G89", "S22", "C2", "", " "))
#plot it
rc <- ggplot(data = sumr) +
geom_linerange(aes(x = acc, ymin = mean - se, ymax = mean + se, color = soil)) + # this is only the line spanning the SE
geom_point(aes(x = acc, y = mean, shape = acc, color = soil)) + # this is the Mean; a symbol for every genotype
facet_wrap(~soil, nrow = 1) +
scale_shape_manual(values = c(NA, 19, 15, 18, 17, 20, NA, 2, 1, 0, NA, NA), drop=FALSE) + # ! # give solid shape to resistant, open ones to susceptible lines
scale_color_manual(values = Kolor, labels = soil_names) +
scale_fill_manual(labels = soil_names) +
theme_classic() +
scale_y_continuous(labels = function(x){paste(x, "-")},
sec.axis = dup_axis(breaks = 0),
expand = c(0, 0),
breaks = c(0,1,2,3,4,5)) + # put a fake right y-axis as border...
coord_cartesian(ylim = c(0, 6)) + # set explicit range
geom_hline(yintercept = 6) +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y.right = element_blank(), # hide right axis title
axis.text.y = element_blank(),
axis.ticks.y.right = element_blank(),
panel.spacing = unit(0, "lines"),
strip.background = element_blank(),
strip.text.x = element_blank(),
legend.title = element_blank(),
panel.background = element_blank(),
panel.grid = element_blank(),
legend.spacing.x = unit(0.02, 'cm'),
legend.spacing.y = unit(0.02, 'cm')) +
labs(tag="(b)",
y=expression(""),
x=expression("Genotype")) +
guides(shape = guide_legend(ncol = 2, override.aes = list(shape = c(NA, 19, 15, 18, 17, 20, NA, 2, 1, 0, NA, NA))),
color = guide_legend(ncol = 2, override.aes = list(linetype = c(0,0))))
## put the two panels A + B & Save
props2 <- ggpubr::ggarrange(rh, rc, widths = c(1,4))
#ggsave("RRI_BoxplotwithInteractionplot.eps", props2, units="cm", width=18, height=6, dpi=600) # I save only once.
#ggsave("RRI_BoxplotwithInteractionplot.png", props2, units="cm", width=18, height=6, dpi=200) # png
#ggsave("RRI_BoxplotwithInteractionplot.jpg", props2, units="cm", width=18, height=6, dpi=200) # jpg
```
\newpage
# Analysis of qPCR data
## Summary of qPCR data (mean & SD for each genotype in each soil) -> Supp Tab 5 (for this table I used the full data including data on C2 in F & W soils)
```{r fungi stack, echo=FALSE, message=FALSE}
###### Stacked fungis
# Calc mean over soil&acc for each fungi
sum.fungi.mean.sd <- Topf18.FUNGI %>% group_by(soil, acc) %>%
summarise(meanApha= mean(Apha, na.rm = TRUE),
sdApha= sd(Apha, na.rm = TRUE),
meanFave= mean(Fave, na.rm = TRUE),
sdFave= sd(Fave, na.rm = TRUE),
meanFoxy= mean(Foxy, na.rm = TRUE),
sdFoxy= sd(Foxy, na.rm = TRUE),
meanFredo= mean(Fredo, na.rm = TRUE),
sdFredo= sd(Fredo, na.rm = TRUE),
meanFsol= mean(Fsol, na.rm = TRUE),
sdFsol= sd(Fsol, na.rm = TRUE),
meanPhoma= mean(Phoma, na.rm = TRUE),
sdPhoma= sd(Phoma, na.rm = TRUE),
meanPult= mean(Pult, na.rm = TRUE),
sdPult= sd(Pult, na.rm = TRUE),
meanRsol= mean(Rsol, na.rm = TRUE),
sdRsol= sd(Rsol, na.rm = TRUE),
meanAMF= mean(AMF, na.rm = TRUE),
sdAMF= sd(AMF, na.rm = TRUE),
meanCros= mean(Cros, na.rm = TRUE),
sdCros= sd(Cros, na.rm = TRUE))
```
## Analysis of qPCR data
For the data analysis, I kick-out entries for C2 in F and W, because I only have 1-2 reps per taxa in F soil and only 1 rep for each taxa in W soil.
```{r clean data, echo=FALSE}
Topf18.FUNGI[Topf18.FUNGI$soil=="F" & Topf18.FUNGI$acc=="C2",7:36] <- NA
Topf18.FUNGI[Topf18.FUNGI$soil=="W" & Topf18.FUNGI$acc=="C2",7:36] <- NA
```
### Plot: Stacks of the fungi --> FIGURE 2
```{r plot stacks, echo=FALSE, message=FALSE}
# prep data
sum.fungi.accsoil <- Topf18.FUNGI %>% group_by(soil, acc) %>%
summarise(Apha= mean(Apha, na.rm = TRUE),
Fave= mean(Fave, na.rm = TRUE),
Foxy= mean(Foxy, na.rm = TRUE),
Fredo= mean(Fredo, na.rm = TRUE),
Fsol= mean(Fsol, na.rm = TRUE),
Phoma= mean(Phoma, na.rm = TRUE),
Pult= mean(Pult, na.rm = TRUE),
Rsol= mean(Rsol, na.rm = TRUE),
AMF= mean(sqrt(AMF), na.rm = TRUE), # sqrt AMF!
Cros= mean(Cros, na.rm = TRUE))
sum.fungi.accsoil$acc <- factor(sum.fungi.accsoil$acc, c("S91", "S134", "G78", "C1", "S64", "G89", "S22", "C2")) # order based on SDWrel in Screen17
sum.fungi.accsoil.long <- reshape2::melt(sum.fungi.accsoil, id = c("soil", "acc")) # put table in long format...
sum.fungi.accsoil.long$variable <- factor(sum.fungi.accsoil.long$variable, levels=c("AMF", "Cros", "Apha", "Fsol", "Foxy", "Rsol", "Pult", "Fave", "Fredo", "Phoma"))
sum.fungi.accsoil.long <- sum.fungi.accsoil.long[order(sum.fungi.accsoil.long$variable), ] # aus irgend einem grund brauch ich dieses reorder, weil einfach factor() reich nicht...
# Plot
myKolor = c("#A1D99B", "#800026", "darkgreen", "gray22", "gray60", "black", "gray77", "blue", "orange", "#FF3399")
stacks <- ggplot(sum.fungi.accsoil.long, aes(x = acc, fill=variable)) +
geom_hline(yintercept = c(-100, 500, 0, 1000, 1500), size = 0.3) +
geom_bar(data = subset(sum.fungi.accsoil.long, variable %in% c("Fsol", "Apha", "Fave", "Foxy", "Fredo", "Pult", "Rsol", "Phoma")), aes(y = value), stat = "identity") +
geom_bar(data = subset(sum.fungi.accsoil.long, variable %in% c("AMF", "Cros")), aes(y = -value), stat = "identity") +
scale_fill_manual(values = myKolor, labels = c("AMF",
expression(italic(A.~euteiches)), expression(italic(C.~rosea)),
expression(italic(F.~avenaceum)), expression(italic(F.~oxysporum)), expression(italic(F.~redolens)),
expression(italic(F.~solani)), expression(italic(D.~pinodella)), expression(italic(P.~ultimum)),
expression(italic(R.~solani))
)) +
scale_y_continuous(breaks = c(-100,0,500, 1000, 1500)) +
facet_wrap(~soil, nrow = 1, labeller=labeller(soil = soil_names)) +
theme_classic() +
theme(legend.title = element_blank(),
legend.key.size = unit(0.5,"line"),
legend.text = element_text(size=8),
legend.text.align = 0,
strip.background = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_text(size=8),
axis.line = element_blank(),
axis.text.x = element_text(angle=45, size = 6, vjust=1),
axis.text.y = element_text(size=5),
axis.ticks.y = element_blank()) +
labs(y=expression(paste("Microbial quantities"))) +
theme(plot.margin = unit(c(1,1,2,1), "lines")) +
geom_text(data=data.frame(soil="F"), label="NA", x=8, y=150, size=2.5, inherit.aes = FALSE) +
geom_text(data=data.frame(soil="W"), label="NA", x=8, y=150, size=2.5, inherit.aes = FALSE) +
annotation_custom(ggpubr::text_grob("resistant", size=6),
xmin=2.5,xmax=2.5,ymin=-770,ymax=-770) +
annotation_custom(ggpubr::text_grob("susc.", size=6),
xmin=7,xmax=7,ymin=-770,ymax=-770) +
annotation_custom(grid::linesGrob(), xmin = 0.25, xmax = 5.25, ymin = -690, ymax = -690) +
annotation_custom(grid::linesGrob(gp=grid::gpar(lty=2)), xmin = 5.75, xmax = 8.25, ymin = -690, ymax = -690) +
coord_cartesian(clip = "off")
stacks
#ggsave("fungiStack_NS.eps", stacks, units="cm", width=18, height=7, dpi=600) # I save only once.
#ggsave("fungiStack_NS.png", stacks, units="cm", width=18, height=7, dpi=200) # png
#ggsave("fungiStack_NS.jpg", stacks, units="cm", width=18, height=7, dpi=200) # jpg
```
### NMDS
#### First, Data prep: make a DF that contains the mean fungal quants and phenotypic data (SDWRel & RRI) -> "COMBO".
```{r Combo DF, echo=FALSE}
Topf18.FUNGI.MEANS <- Topf18.FUNGI[,c(1,2,3,4,5,6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36)] # this DF contains the mean (between ONE & TWO) qPCR values for each sample only
# then I replace/impute the missing qPCR values
Topf18.FUNGI.MEANS.NONA <- Topf18.FUNGI.MEANS
for (i in thefungis) {
for (sl in levels(Topf18.FUNGI.MEANS.NONA$soil)) {
for (acs in levels(Topf18.FUNGI.MEANS.NONA$acc)) {
Topf18.FUNGI.MEANS.NONA[Topf18.FUNGI.MEANS.NONA$soil == sl & Topf18.FUNGI.MEANS.NONA$acc == acs,][[i]] <-
Topf18.FUNGI.MEANS.NONA[Topf18.FUNGI.MEANS.NONA$soil == sl & Topf18.FUNGI.MEANS.NONA$acc == acs,][[i]] %>%
replace_na(
mean(Topf18.FUNGI.MEANS.NONA[Topf18.FUNGI.MEANS.NONA$soil == sl & Topf18.FUNGI.MEANS.NONA$acc == acs,][[i]],
na.rm = TRUE)
)
}
}
}
# However, C2 in F and W are set to NA for all samples, because, again, I only have 1 (max. 2 in some cases) qPCR observations for theses samples. So I do not want to analyze them.
Topf18.FUNGI.MEANS.NONA[Topf18.FUNGI.MEANS.NONA$soil=="F" & Topf18.FUNGI.MEANS.NONA$acc=="C2",7:16] <- NA
Topf18.FUNGI.MEANS.NONA[Topf18.FUNGI.MEANS.NONA$soil=="W" & Topf18.FUNGI.MEANS.NONA$acc=="C2",7:16] <- NA
# Then prep the actual COMBO DF --> this is the DF I use for the GAM analysis
xxx <- Topf18.FUNGI.MEANS[,-c(2:6)] # throw out extra design variables
Topf18.COMBO.NS <- merge(Topf18.4.8.NS[,c(1:7,17,27)], xxx, "LABEL", all = TRUE)
Topf18.COMBO.NS <- droplevels(Topf18.COMBO.NS)
rm(xxx)
# and do the same for a NONA-COMBO DF --> this is the DF I use for the NMDS and PERMANOVA analysis
xxx <- Topf18.FUNGI.MEANS.NONA[,-c(2:6)] # throw out extra design variables
Topf18.COMBO.NS.NONA <- merge(Topf18.4.8.NS[,c(1:7,17,27)], xxx, "LABEL", all = TRUE)
Topf18.COMBO.NS.NONA <- droplevels(Topf18.COMBO.NS.NONA)
rm(xxx)
```
...some more prep...
```{r prep data for NMDS, echo=FALSE}
# Prep data: bring factors in good order for plotting
Topf18.COMBO.NS.NONA$acc <- factor(Topf18.COMBO.NS.NONA$acc, c("C1", "S91", "S134", "S64", "G78", "C2", "S22", "G89")) # put genotypes in right order for plotting
Topf18.COMBO.NS.NONA$reslevel <- dplyr::recode(Topf18.COMBO.NS.NONA$reslevel, R = "resistant", S = "susceptible")
# prep data for NMDS: I even have to delete the C2-F and C2-W entries entirely for the NMDS analysis (because their all NA)
Topf18.COMBO.NS.NONA.xxx <- subset(Topf18.COMBO.NS.NONA, !(soil=="F" & acc=="C2"))
Topf18.COMBO.NS.NONA.xxx <- subset(Topf18.COMBO.NS.NONA.xxx, !(soil=="W" & acc=="C2"))
```
#### Second, do the NMDS & PERMANOVA: 5 Plots are produced; 1 over 4 soils, as an inset in the 3 soil plot; 1 over 3 soils and then 3 plots for each of the infested soils.... Env.fit arrows are added for the the five fungi with the highest r2 with the ordination. PERMANOVA R2 for the factors soi, acc or reslevel are added as well with corresponding p-vals. --> FIGURE 3
```{r do NMDS, echo=FALSE, warning=FALSE}
# 1. The 4 soils NMDS Plot without legend -> This willgive a little inset graphic in the big graphic
# prep "Adf", you only want the scores, no factors
Adf4 <- Topf18.COMBO.NS.NONA.xxx[, c(10:19)]
# state the NMDS
fung.mds4 <- metaMDS(Adf4, distance = "bray", k = 2, trymax = 50) # makes the object bci.mds using Bray-Curtis ordination
# pull points from MDS
nmds4.1 <- fung.mds4$points[,1] # also found using scores(birdMDS)
nmds4.2 <- fung.mds4$points[,2]
nmds.plot4 <- cbind(Topf18.COMBO.NS.NONA.xxx, nmds4.1, nmds4.2)
nmds.plot4$acc <- factor(nmds.plot4$acc, c("C1", "S91", "S134", "S64", "G78", "C2", "S22", "G89"))
# plot with ggplot
g4 <- ggplot(nmds.plot4, aes(nmds4.1, nmds4.2)) +
annotate("text", x=0.5, y=0.6, label= "4 soils", angle = 0, size = 3) +# add fake title inseide Plot
geom_point(aes(color = soil), size=1.1) +
scale_color_manual(values = Kolor, labels = soil_nms) +
scale_fill_manual(values = Kolor) +
scale_y_continuous(breaks = c(-0.5, 0, 0.5)) +
scale_x_continuous(breaks = c(-0.5, 0, 0.5)) +
theme_bw() +
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
legend.position = c(0.15,0.2),
legend.title = element_blank(),
legend.background = element_rect(fill = "transparent"),
legend.box.margin = margin(0, 0, 0, 0),
legend.key.height = unit(0.2,"cm"),
panel.background = element_blank(),
panel.grid = element_blank(),
plot.title = element_text(size = 10),
axis.title=element_blank(),
plot.margin= grid::unit(c(0, 0, 0, 0), "in")) +
guides(shape=FALSE, fill=FALSE) #guide_legend(override.aes=list(fill=NA))
## 2. 3 infested soils
# prep "Adf", you only want the scores, no factors
Adf3 <- Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil!= "F", c(10:19)]
# state the NMDS
fung.mds3 <- metaMDS(Adf3, distance = "bray", k = 2, trymax = 50) # makes the object bci.mds using Bray-Curtis ordination
# pull points from MDS
nmds3.1 <- fung.mds3$points[,1] # also found using scores(birdMDS)
nmds3.2 <- fung.mds3$points[,2]
nmds.plot3 <- cbind(Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil!= "F", ], nmds3.1, nmds3.2)
nmds.plot3$acc <- factor(nmds.plot3$acc, c("C1", "S91", "S134", "S64", "G78", "C2", "S22", "G89"))
#PERMANOVA: The r2 and p-vals are then plotted in the plot
fung.dist3 <- vegdist(Adf3)
set.seed(3825)
adonis(fung.dist3 ~ rep + soil*acc, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil!= "F", ])
adonis(fung.dist3 ~ rep + soil*reslevel, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil!= "F", ])
# Prepare the 10 arrows for the NMDS-Plot
fit3 <- envfit(fung.mds3, Adf3) # "envfit" fittet variabeln auf die Ordination; hier einfach meine 10 Pilze
arrow3 <- data.frame(fit3$vectors$arrows, R = fit3$vectors$r, P = fit3$vectors$pvals) # Koordinaten der Vektoren der Variabeln
arrow3$FG <- rownames(arrow3) # Pilznamen
# plot mit ggplot
sze = 2.8 # this is font size 8
g3 <- ggplot(nmds.plot3, aes(nmds3.1, nmds3.2)) +
geom_segment(data = arrow3[arrow3$R>0.30,], aes(x=0, y=0, xend=NMDS1*arrow3[arrow3$R>0.30,]$R*1.1, yend=NMDS2*arrow3[arrow3$R>0.30,]$R*1.1), # only show the 5 arrows/fungis with the highest R2
linetype = 1,
alpha=1,
size = 0.3,
arrow = arrow(length = unit(0.15, "cm"))) +
geom_point(aes(shape = acc, color = soil), size=1.4) +
scale_shape_manual(values = c(15, 0, 19, 1, 17, 2, 20, 18)) +
scale_color_manual(values = Kolor[2:4], labels = soil_nms) +
scale_fill_manual(values = Kolor[2:4]) +
scale_y_continuous(breaks = c(-0.5, 0, 0.5)) +
scale_x_continuous(breaks = c(-0.5, 0, 0.5)) +
coord_cartesian(xlim = c(-0.7,0.7), ylim = c(-0.7,0.7)) +
annotate("text", x=0.64, y=0.034, label= "AMF", angle = 0, alpha=1, size = 2.8) + # add Fungi names manually
annotate("text", x=-0.33, y=-0.39, label= "F. sol", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=-0.06, y=-0.43, label= "C. ros.", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=0.155, y=-0.335, label= "F. oxy.", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=-0.39, y=0.15, label= "A. eut.", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=0.45, y=-0.65, label=paste('Stress =', round(fung.mds3$stress,2)), size=2.5) + # add stress-value to plot
annotate("text", x=-0.7, y=0.7, hjust = 0, label= "PERMANOVA", size = sze) +
annotate("text", x=-0.7, y=0.65, hjust = 0, label= "A: soil .41***", size = sze) + # PERMANOVA results
annotate("text", x=-0.7, y=0.6, hjust = 0, label= " soil*genotype .15***", size = sze) +
annotate("text", x=-0.7, y=0.55, hjust = 0, label= " genotype .14***", size = sze) +
annotate("text", x=-0.7, y=0.48, hjust = 0, label= "B: soil .41***", size = sze) +
annotate("text", x=-0.7, y=0.43, hjust = 0, label= " res. level .1***", size = sze) +
annotate("text", x=-0.7, y=0.38, hjust = 0, label= " soil*res. level .07***", size = sze)+
theme_bw() +
theme(legend.position = c(0.15,0.2),
legend.title = element_blank(),
legend.background = element_rect(fill = "transparent"),
legend.box.margin = margin(0, 0, 0, 0),
legend.key.height = unit(0.2,"cm"),
panel.background = element_blank(),
axis.title.x = element_blank(),
panel.grid = element_blank(),
plot.title = element_text(size = 10)) +
guides(shape=FALSE, fill=FALSE) + #guide_legend(override.aes=list(fill=NA))
ylab("NMDS2") +
ggtitle("3 infested soils")
## 3. H soil
# prep "Adf", you only want the scores, no factors
AdfH <- Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "H", c(10,12,14:19)] # take out Fave & Fredo in H
# state the NMDS
fung.mdsH <- metaMDS(AdfH, distance = "bray", k = 2, trymax = 50) #makes the object bci.mds using Bray-Curtis ordination
# pull points from MDS
nmdsH.1 <- fung.mdsH$points[,1] # also found using scores(birdMDS)
nmdsH.2 <- fung.mdsH$points[,2]
nmds.plotH <- cbind(Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "H", c(1:10,12,14:19)], nmdsH.1, nmdsH.2) # take out Fave & Fredo in H
nmds.plotH$acc <- factor(nmds.plotH$acc, c("C1", "S91", "S134", "S64", "G78", "C2", "S22", "G89"))
#PERMANOVA: The r2 and p-vals are then plotted in the plot
fung.distH <- vegdist(AdfH)
set.seed(3825)
adonis(fung.distH ~ rep + acc, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "H", ])
adonis(fung.distH ~ rep + reslevel, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "H", ])
# Prepare the 10 arrows for the NMDS-Plot
fitH <- envfit(fung.mdsH, AdfH) # "envfit" fittet variabeln auf die Ordination; hier einfach meine 10 Pilze
arrowH <- data.frame(fitH$vectors$arrows, R = fitH$vectors$r, P = fitH$vectors$pvals) # Koordinaten der Vektoren der Variabeln
arrowH$FG <- rownames(arrowH) # Pilznamen
# plot mit ggplot
gH <- ggplot(nmds.plotH, aes(nmdsH.1, nmdsH.2)) +
geom_segment(data = arrowH[arrowH$R>0.22,], aes(x=0, y=0, xend=NMDS1*arrowH[arrowH$R>0.22,]$R*1.1, yend=NMDS2*arrowH[arrowH$R>0.22,]$R*1.1), # only show the 5 arrows/fungis with the highest R2
linetype = 1,
alpha=1,
size = 0.3,
arrow = arrow(length = unit(0.15, "cm"))) +
geom_point(aes(shape = acc), color = Kolor[2], fill= Kolor[2], size=1.4) +
scale_shape_manual(values = c(17, 19, 15, 20, 18, 0, 1, 2)) +
stat_ellipse(aes(lty=factor(reslevel)), alpha=0.2, size = 0.5, geom = "polygon", color = Kolor[2], fill=NA) +
scale_y_continuous(breaks = c(-0.5, 0, 0.5)) +
scale_x_continuous(breaks = c(-0.5, 0, 0.5)) +
coord_cartesian(xlim = c(-0.7,0.7), ylim = c(-0.7,0.7)) +
annotate("text", x=-0.08, y=0.74, label= "A. eut", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=0.41, y=0.055, label= "F. oxy.", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=0.6, y=0.02, label= "F. sol.", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=-0.56, y=-0.41, label= "AMF", angle = 0, alpha=1, size = 2.8) +
annotate("text", x=0.47, y=-0.088, label= "C. ros.", fontface = 'italic', angle = 0, alpha=1, size = 2.8) +
annotate("text", x=-0.7, y=0.7, hjust = 0, label= "PERMANOVA", size = sze) +
annotate("text", x=-0.7, y=0.65, hjust = 0, label= "A: genotype .59***", size = sze) +
annotate("text", x=-0.7, y=0.58, hjust = 0, label= "B: res. level .39***", size = sze) +
annotate("text", x=0.45, y=-0.65, label=paste('Stress =', round(fung.mdsH$stress,2)), size=2.5) +
ggtitle("Kirchlindach") +
theme_bw() +
theme(legend.title = element_blank(),
legend.background = element_rect(fill = "transparent"),
legend.box.margin = margin(0, 0, 0, 0),
legend.key.height = unit(0.2,"cm"),
panel.background = element_blank(),
panel.grid = element_blank(),
plot.title = element_text(size = 10),
axis.title = element_blank(),
legend.spacing.x = unit(0.02, 'cm'),
legend.spacing.y = unit(0.02, 'cm')) +
guides(fill = guide_legend(colour="black"),
shape = guide_legend(override.aes = list(shape = c(17, 19, 15, 20, 18, 0, 1, 2), color="black", fill="black")),
lty = guide_legend(override.aes = list(color="black")))
## 4. L soil
# prep "Adf", you only want the scores, no factors
AdfL <- Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "L", c(10:12,14:19)] # take out Fredo in L
# state the NMDS
fung.mdsL <- metaMDS(AdfL, distance = "bray", k = 2, trymax = 50) #makes the object bci.mds using Bray-Curtis ordination
# pull points from MDS
nmdsL.1 <- fung.mdsL$points[,1] # also found using scores(birdMDS)
nmdsL.2 <- fung.mdsL$points[,2]
nmds.plotL <- cbind(Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "L", c(1:12, 14:19)], nmdsL.1, nmdsL.2) # take out Fredo in L
nmds.plotL$acc <- factor(nmds.plotL$acc, c("C1", "S91", "S134", "S64", "G78", "C2", "S22", "G89"))
#PERMANOVA: The r2 and p-vals are then plotted in the plot
fung.distL <- vegdist(AdfL)
set.seed(3825)
adonis(fung.distL ~ rep + acc, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "L", ])
adonis(fung.distL ~ rep + reslevel, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "L", ])
# Prepare the 10 arrows for the NMDS-Plot
fitL <- envfit(fung.mdsL, AdfL) # "envfit" fittet variabeln auf die Ordination; hier einfach meine 10 Pilze
arrowL <- data.frame(fitL$vectors$arrows, R = fitL$vectors$r, P = fitL$vectors$pvals) # Koordinaten der Vektoren der Variabeln
arrowL$FG <- rownames(arrowL) # Pilznamen
# plot mit ggplot
gL <- ggplot(nmds.plotL, aes(nmdsL.1, nmdsL.2)) +
geom_segment(data = arrowL[arrowL$R>0.47,], aes(x=0, y=0, xend=NMDS1*arrowL[arrowL$R>0.47,]$R*1.1, yend=NMDS2*arrowL[arrowL$R>0.47,]$R*1.1), # only show the 5 arrows/fungis with the highest R2
linetype = 1,
alpha=1,
size = 0.3,
arrow = arrow(length = unit(0.15, "cm"))) +
geom_point(aes(shape = acc), color = Kolor[3], fill= Kolor[3], size=1.4) +
scale_shape_manual(values = c(17, 19, 15, 20, 18, 0, 1, 2)) +
stat_ellipse(aes(lty=factor(reslevel)), alpha=0.2, size = 0.5, geom = "polygon", color = Kolor[3], fill=NA) +
scale_y_continuous(breaks = c(-0.5, 0, 0.5)) +
scale_x_continuous(breaks = c(-0.5, 0, 0.5)) +
coord_cartesian(xlim = c(-0.7,0.7), ylim = c(-0.7,0.7)) +
annotate("text", x=-0.32, y=-0.43, label= "A. eut.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=-0.25, y=-0.55, label= "F. oxy.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=-0.65, y=-0.04, label= "F sol.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=0.1, y=-0.6, label= "P. ult.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=0.68, y=-0.29, label= "AMF", alpha=1, size = 2.8) + # add Fungi names manually
annotate("text", x=-0.7, y=0.7, hjust = 0, label= "PERMANOVA", size = sze) +
annotate("text", x=-0.7, y=0.65, hjust = 0, label= "A: genotype .46**", size = sze) +
annotate("text", x=-0.7, y=0.58, hjust = 0, label= "B: res. level .21**", size = sze) +
annotate("text", x=0.45, y=-0.65, label=paste('Stress =', round(fung.mdsL$stress,2)), size=2.5) +
ggtitle("Puch") +
theme_bw() +
theme(legend.title = element_blank(),
legend.background = element_rect(fill = "transparent"),
legend.box.margin = margin(0, 0, 0, 0),
legend.key.height = unit(0.2,"cm"),
panel.background = element_blank(),
panel.grid = element_blank(),
plot.title = element_text(size = 10),
legend.spacing.x = unit(0.02, 'cm'),
legend.spacing.y = unit(0.02, 'cm')) +
guides(fill = guide_legend(colour="black"),
shape = guide_legend(override.aes = list(shape = c(17, 19, 15, 20, 18, 0, 1, 2), color="black", fill="black")),
lty = guide_legend(override.aes = list(color="black"))) +
xlab("NMDS1") +
ylab("NMDS2")
## 5. W soil
# prep "Adf", you only want the scores, no factors
AdfW <- Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "W", c(10, 12:19)] # take out Fave in W
# state the NMDS
fung.mdsW <- metaMDS(AdfW, distance = "bray", k = 2, trymax = 50) #makes the object bci.mds using Bray-Curtis ordination
# pull points from MDS
nmdsW.1 <- fung.mdsW$points[,1] # also found using scores(birdMDS)
nmdsW.2 <- fung.mdsW$points[,2]
nmds.plotW <- cbind(Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "W", c(1:10, 12:19)], nmdsW.1, nmdsW.2) # take out Fave in W
nmds.plotW$acc <- factor(nmds.plotW$acc, c("C1", "S91", "S134", "S64", "G78", "C2", "S22", "G89"))
#PERMANOVA: The r2 and p-vals are then plotted in the plot
fung.distW <- vegdist(AdfW)
set.seed(3825)
adonis(fung.distW ~ rep + acc, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "W", ])
adonis(fung.distW ~ rep + reslevel, data = Topf18.COMBO.NS.NONA.xxx[Topf18.COMBO.NS.NONA.xxx$soil== "W", ])
# Prepare the 10 arrows for the NMDS-Plot
fitW <- envfit(fung.mdsW, AdfW) # "envfit" fittet variabeln auf die Ordination; hier einfach meine 10 Pilze
arrowW <- data.frame(fitW$vectors$arrows, R = fitW$vectors$r, P = fitW$vectors$pvals) # Koordinaten der Vektoren der Variabeln
arrowW$FG <- rownames(arrowW) # Pilznamen
# plot mit ggplot
gW <- ggplot(nmds.plotW, aes(nmdsW.1, nmdsW.2)) +
geom_segment(data = arrowW[arrowW$R>0.32,], aes(x=0, y=0, xend=NMDS1*arrowW[arrowW$R>0.32,]$R*1.1, yend=NMDS2*arrowW[arrowW$R>0.32,]$R*1.1), # only show the 5 arrows/fungis with the highest R2
linetype = 1,
alpha=1,
size = 0.3,
arrow = arrow(length = unit(0.15, "cm"))) +
geom_point(aes(shape = acc), color = Kolor[4], fill= Kolor[4], size=1.4) +
scale_shape_manual(values = c(17, 19, 15, 20, 18, 1, 2)) +
stat_ellipse(aes(lty=factor(reslevel)), alpha=0.2, size = 0.5, geom = "polygon", color = Kolor[4], fill=NA) +
scale_y_continuous(breaks = c(-0.5, 0, 0.5)) +
scale_x_continuous(breaks = c(-0.5, 0, 0.5)) +
coord_cartesian(xlim = c(-0.7,0.7), ylim = c(-0.7,0.7)) +
annotate("text", x=-0.25, y=-0.6, label= "A. eut.", fontface = 'italic', alpha=1, size = 2.8) + # add Fungi names manually
annotate("text", x=0.4, y=-0.1, label= "F. oxy.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=0.38, y=-0.4, label= "F. redo.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=0.16, y=-0.39, label= "F. sol.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=0.33, y=-0.25, label= "C. ros.", fontface = 'italic', alpha=1, size = 2.8) +
annotate("text", x=-0.7, y=0.7, hjust = 0, label= "PERMANOVA", size = sze) +
annotate("text", x=-0.7, y=0.65, hjust = 0, label= "A: genotype .33*", size = sze) +
annotate("text", x=-0.7, y=0.58, hjust = 0, label= "B: res. level .18**", size = sze) +
annotate("text", x=0.45, y=-0.65, label=paste('Stress =', round(fung.mdsW$stress,2)), size=2.5) +
ggtitle("Neu-Eichenberg") +
theme_bw() +
theme(legend.title = element_blank(),
legend.background = element_rect(fill = "transparent"),
legend.box.margin = margin(0, 0, 0, 0),
legend.key.height = unit(0.2,"cm"),
panel.background = element_blank(),
panel.grid = element_blank(),
plot.title = element_text(size = 10),
axis.title.y = element_blank(),
legend.spacing.x = unit(0.02, 'cm'),
legend.spacing.y = unit(0.02, 'cm')) +
guides(fill = guide_legend(colour="black"),
shape = guide_legend(override.aes = list(shape = c(17, 19, 15, 20, 18, 1, 2), color="black", fill="black")),
lty = guide_legend(override.aes = list(color="black"))) +
xlab("NMDS1")
## 6. Now, put all plot together
# A: get legends (note the 4 soils legend is already in the big panel), and arranghe them together
thelegendsoils <- ggpubr::get_legend(g4 + theme(legend.margin = margin(0, 0, 0, 0)) + guides(lty=FALSE)) # extract the legend for the soils from the 4 soils plot
thelegendAccs <- ggpubr::get_legend(gH + theme(legend.margin = margin(0, 0, 0, 0)) + guides(lty=FALSE)) # extract the legend for the accs from one of the plots
thelegendRes <- ggpubr::get_legend(gH + theme(legend.margin = margin(0, 0, 0, 0)) +
guides(shape=FALSE, lty = guide_legend(override.aes = list(color ="black"))))
# B: produce the 4 soils inset in the 3 soils plot
g4_grob <- ggplotGrob(g4 + theme(legend.position = "none"))
g3plus <- g3 + annotation_custom(grob = g4_grob, xmin = 0.3, xmax = 0.75, ymin = 0.3, ymax = 0.75)
# C: put soil and genoytpe legends in g3plus
g3plusplus <- g3plus + theme(legend.position="none") + annotation_custom(grob = thelegendsoils, xmin = -0.80, xmax = -0.5, ymin = -0.2, ymax = 0)
g3plusplusplus <- g3plusplus + annotation_custom(grob = thelegendAccs, xmin = -0.75, xmax = -0.5, ymin = -0.67, ymax = -0.27)
# D: put reslevel legend in gH
gHplus <- gH + theme(legend.position="none") + theme(axis.text = element_blank()) + annotation_custom(grob = thelegendRes, xmin = -0.7, xmax = -0.35, ymin = -0.75, ymax = -0.6)
# E: arrange the 4 plots
wow <- cowplot::plot_grid(
g3plusplusplus + theme(axis.text.x = element_blank(), axis.title = element_text(size=8)),
gHplus,
gL + theme(legend.position="none") + theme(axis.title = element_text(size=8)),
gW + theme(legend.position="none") + theme(axis.text.y = element_blank(), axis.title = element_text(size=8)),
nrow = 2,
rel_widths = c(1.11, 1, 1.11, 1))
wow
# D: save that beautiful plot
#ggsave("4plus.eps", wow, units="cm", width=18, height=18, dpi=600) # 180mm is full width for NewPhyt
#ggsave("4plus.png", wow, units="cm", width=18, height=18, dpi=200) # png
#rm(Adf4, Adf3, AdfH, AdfL, AdfW, arrow3, arrowH, arrowL, arrowW, fit3, fitH, fitL, fitW, fung.mds3, fung.mdsH, fung.mds4, fung.mdsL, fung.mdsW, fung.dist3, fung.distH, fung.distL, fung.distW, nmds.plot4, nmds.plot3, nmds.plotH, nmds.plotL, nmds.plotW, fung.dist3, fung.distH,fung.distL, fung.distW, nmds4.1, nmds4.2, nmds3.1, nmds3.2, nmdsH.1, nmdsH.2, nmdsL.1, nmdsL.2, nmdsW.1, nmdsW.2, g4, g4_grob, g3, g3plus, gH, gL, gW)
```
### GAM Analysis of SDWrel. ~ fungi
1) I backward select the variables (fungi) from a full model containing all fungi, without factors soil or acc. At each step I exlude the variable with the highest p-value. I set k=5 manually, in order to avoid too much wiggeliness.
```{r GAM 100noacc, echo=FALSE}
d3ta <- Topf18.COMBO.NS %>% filter (soil!="F")
modGAM_100 <- gam(s.dw.ratioSNS ~
s(Apha, bs="cs", k=5) +
s(Fsol, bs="cs", k=5) +
s(Fave, bs="cs", k=5) +
s(Fredo, bs="cs", k=5) +
s(Foxy, bs="cs", k=5) +
s(Phoma, bs="cs", k=5) +
s(Pult, bs="cs", k=5) +
s(Rsol, bs="cs", k=5) +
s(Cros, bs="cs", k=5) +
s(AMF, bs="cs", k=5),
data = d3ta)
#
modelxxx <- modGAM_100
# model diagnostic
par(mfrow = c(2,2))
gam.check(modelxxx)
# model inspection
plot.gam(modelxxx, pages=1, scheme = 2)
summary.gam(modelxxx)
AIC(modelxxx)
```
-> Pult rausnehmen:
```{r GAM 99noacc1, echo=FALSE}
modGAM_99 <- gam(s.dw.ratioSNS ~
s(Apha, bs="cs", k=5) +
s(Fsol, bs="cs", k=5) +
s(Fave, bs="cs", k=5) +
s(Fredo, bs="cs", k=5) +
s(Foxy, bs="cs", k=5) +
s(Phoma, bs="cs", k=5) +
#s(Pult, bs="cs", k=5) +
s(Rsol, bs="cs", k=5) +
s(Cros, bs="cs", k=5) +
s(AMF, bs="cs", k=5),
data = d3ta)
#
modelxxx <- modGAM_99
# model diagnostic
par(mfrow = c(2,2))
gam.check(modelxxx)
# model inspection
plot.gam(modelxxx, pages=1, scheme = 2)
summary.gam(modelxxx)
AIC(modelxxx)
```
-> Phoma rausnehmen: