library(dplyr)
library(ape)
library(reshape2)
library(scales)
library(knitr)
library(ggrepel)
library(nlme)
library(lme4)
library(sciplot) # se() function
library(apeglm)
library(pheatmap)
library(picante)
library(emmeans)
library(multcomp)
library(multcompView)
library(purrr) # functions for lists
library(car) # Anova() function (for glmer)
library(ggvegan) # customize PRC plot
# colour palettes
library(viridis)
library(RColorBrewer)
sessionInfo()
pPatho
library(phyloseq)
library(microbiome)
library(microbiomeutilities) # format_to_besthit()
library(ggpubr) # ggarrange()
library(plyr)
library(dplyr)
library(ape)
library(reshape2)
library(scales)
library(knitr)
library(ggrepel)
library(nlme)
library(lme4)
library(sciplot) # se() function
library(apeglm)
library(pheatmap)
library(picante)
library(emmeans)
library(multcomp)
library(multcompView)
library(purrr) # functions for lists
library(car) # Anova() function (for glmer)
library(ggvegan) # customize PRC plot
# colour palettes
library(viridis)
library(RColorBrewer)
sessionInfo()
ggsave(plot = pPatho.all, "./figures/Pathogens_total.png", h = 7, w = 10)
ggsave(plot = pPatho, "./figures/Pathogens_all.png", h = 7, w = 10)
ggsave(plot = pPatho.Ser, "./figures/Pathogens_Serratia.png", h = 7, w = 10)
library(phyloseq)
library(microbiome)
library(microbiomeutilities) # format_to_besthit()
library(ggpubr) # ggarrange()
library(plyr)
library(dplyr)
library(ape)
library(reshape2)
library(scales)
library(knitr)
library(ggrepel)
library(nlme)
library(lme4)
library(sciplot) # se() function
library(apeglm)
library(pheatmap)
library(picante)
library(emmeans)
library(multcomp)
library(multcompView)
library(purrr) # functions for lists
library(car) # Anova() function (for glmer)
library(ggvegan) # customize PRC plot
# colour palettes
library(viridis)
library(RColorBrewer)
sessionInfo()
CFl
# per diet
CFl <- subset_samples(pstot.g.r, Diet == "CF" & Type == "larvae")
CFl <- prune_taxa(taxa_sums(otu_table(CFl)) > 0, CFl)
CFl
# per diet
CFl <- subset_samples(pstot.g.r, Diet == "CF" & Type == "larvae")
CFl <- prune_taxa(taxa_sums(otu_table(CFl)) > 0, CFl)
CSl <- subset_samples(pstot.g.r, Diet == "CS" & Type == "larvae")
CSl <- prune_taxa(taxa_sums(otu_table(CSl)) > 0, CSl)
CMl <- subset_samples(pstot.g.r, Diet == "CM" & Type == "larvae")
CMl <- prune_taxa(taxa_sums(otu_table(CMl)) > 0, CMl)
# all diets, larvae
pstot.l <- subset_samples(pstot.g.r, Type == "larvae")
pstot.l <- prune_taxa(taxa_sums(otu_table(pstot.l)) > 0, pstot.l)
# per diet, larvae
CFl <- subset_samples(pstot.g.r, Diet == "CF" & Type == "larvae")
CFl <- prune_taxa(taxa_sums(otu_table(CFl)) > 0, CFl)
CSl <- subset_samples(pstot.g.r, Diet == "CS" & Type == "larvae")
CSl <- prune_taxa(taxa_sums(otu_table(CSl)) > 0, CSl)
CMl <- subset_samples(pstot.g.r, Diet == "CM" & Type == "larvae")
CMl <- prune_taxa(taxa_sums(otu_table(CMl)) > 0, CMl)
# total
resp.l <- as.data.frame(t(abundances(pstot.l))) # response data
#                                                   |_ optional for species scores
env.l  <- meta(pstot.l)                         # metadata
wuf.l  <- distance(pstot.l, "wunifrac")         # distance matrix
env.cfl  <- meta(CFl)
wuf.cfl  <- distance(CFl, "wunifrac")
env.csl  <- meta(CSl)
wuf.csl  <- distance(CSl, "wunifrac")
env.cml  <- meta(CMl)
wuf.cml  <- distance(CMl, "wunifrac")
levels(env.cml$Density)
# calculate dbRDA
dbRDA.wuf.l <- dbrda(wuf.l ~ env.l$Diet * env.l$Density * env.l$Timepoint)
dbRDA.wuf.l
RsquareAdj(dbRDA.wuf.l)
# permutation tests
dbRDA.wuf0.l <- dbrda(wuf.l ~ 1)
anova.cca(dbRDA.wuf0.l, dbRDA.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.l$ContainerID,
type = "free"), nperm = 999))
# by terms
aov.wuf.l <- anova.cca(dbRDA.wuf.l, model = "direct", by="terms",
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.l$ContainerID,
type = "free"), nperm = 999))
aov.wuf.l
# goodness of fit
stressplot(dbRDA.wuf.l) # good fit.
# dispersion test
anova(betadisper(wuf.l, group = interaction(env.l$Diet,
env.l$Density, env.l$Timepoint, drop = T)),
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.l$ContainerID,
type = "free"), nperm = 999))
# Calculate dbRDA
dbRDA.cf.wuf.l <- dbrda(wuf.cfl ~ env.cfl$Density * env.cfl$Timepoint)
RsquareAdj(dbRDA.cf.wuf.l)
# permutation tests
dbRDA.cf.wuf0.l <- dbrda(wuf.cfl ~ 1)
anova(dbRDA.cf.wuf0.l, dbRDA.cf.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cfl$ContainerID,
type = "free"), nperm = 999))
# by terms
aov.cf.wuf.l <- anova.cca(dbRDA.cf.wuf.l, model = "direct", by="terms",
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cfl$ContainerID,
type = "free"), nperm = 999))
aov.cf.wuf.l
# goodness of fit
stressplot(dbRDA.cf.wuf.l) # fit OK.
# dispersion test
anova(betadisper(wuf.cfl, group = interaction(env.cfl$Density,
env.cfl$Timepoint, drop = T)),
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cfl$ContainerID,
type = "free"), nperm = 999))
# Calculate dbRDA
dbRDA.cs.wuf.l <- dbrda(wuf.csl ~ env.csl$Density * env.csl$Timepoint)
RsquareAdj(dbRDA.cs.wuf.l)
# permutation tests
dbRDA.cs.wuf0.l <- dbrda(wuf.csl ~ 1)
anova(dbRDA.cs.wuf0.l, dbRDA.cs.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.csl$ContainerID,
type = "free"), nperm = 999))
# by terms
aov.cs.wuf.l <- anova.cca(dbRDA.cs.wuf.l, model = "direct", by="terms",
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.csl$ContainerID,
type = "free"), nperm = 999))
aov.cs.wuf.l
# goodness of fit
stressplot(dbRDA.cs.wuf.l) # fit OK.
# dispersion test
anova(betadisper(wuf.csl, group = interaction(env.csl$Density,
env.csl$Timepoint, drop = T)),
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.csl$ContainerID,
type = "free"), nperm = 999))
# Calculate dbRDA
dbRDA.cm.wuf.l <- dbrda(wuf.cml ~ env.cml$Density * env.cml$Timepoint)
RsquareAdj(dbRDA.cm.wuf.l)
# permutation tests
dbRDA.cm.wuf0.l <- dbrda(wuf.cml ~ 1)
anova(dbRDA.cm.wuf0.l, dbRDA.cm.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cml$ContainerID,
type = "free"), nperm = 999))
aov.cm.wuf.l <- anova.cca(dbRDA.cm.wuf.l, model = "direct", by="terms",
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cml$ContainerID,
type = "free"), nperm = 999))
aov.cm.wuf.l
# goodness of fit
stressplot(dbRDA.cm.wuf.l) # fit good.
# dispersion test
anova(betadisper(wuf.cml, group = interaction(env.cml$Density,
env.cml$Timepoint, drop = T)),
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cml$ContainerID,
type = "free"), nperm = 999))
# plot samples
plot_ordination(pstot.l, dbRDA.wuf.l, type = "samples", color = "Diet", shape = "Timepoint")
# plot samples
plot_ordination(pstot.l, dbRDA.wuf.l, type = "samples", color = "Diet", shape = "Timepoint") + facet_wrap(~Density)
# plot samples
plot_ordination(pstot.l, dbRDA.wuf.l, type = "samples", color = "Diet", shape = "Timepoint") + facet_grid(Diet~Density)
# plot samples
pLarv <- plot_ordination(pstot.l, dbRDA.wuf.l, justDF = T)
View(pLarv)
pLarv.15 <- subset(pLarv, Timepoint == 15)
ggplot(pLarv.15, aes(x = dbRDA1, y = dbRDA2, color = Density)) + geom_point() + facet_grid(~Diet)
# plot taxa
sppscores(dbRDA.wuf.l) <- resp.l
plot_ordination(pstot.l, dbRDA.wuf.l, type = "taxa", color = "Phylum")
# plot samples
plot_ordination(CFl, dbRDA.cf.wuf.l, type = "samples", color = "Timepoint", shape = "Density")
# plot samples
plot_ordination(CFl, dbRDA.cf.wuf.l, type = "samples", color = "Density", shape = "Timepoint")
# plot samples
plot_ordination(CFl, dbRDA.cf.wuf.l, type = "samples", color = "Timepoint", shape = "Density")
plot_ordination(CSl, dbRDA.cs.wuf.l, type = "samples", color = "Timepoint", shape = "Density")
plot_ordination(CMl, dbRDA.cm.wuf.l, type = "samples", color = "Timepoint", shape = "Density")
aov.cm.wuf.l
dbRDA.wuf.l
RsquareAdj(dbRDA.wuf.l)
# permutation tests
dbRDA.wuf0.l <- dbrda(wuf.l ~ 1)
anova.cca(dbRDA.wuf0.l, dbRDA.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.l$ContainerID,
type = "free"), nperm = 999))
aov.wuf.l
View(aov.wuf.l)
RsquareAdj(dbRDA.cf.wuf.l)
# permutation tests
dbRDA.cf.wuf0.l <- dbrda(wuf.cfl ~ 1)
anova(dbRDA.cf.wuf0.l, dbRDA.cf.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cfl$ContainerID,
type = "free"), nperm = 999))
# by terms
aov.cf.wuf.l <- anova.cca(dbRDA.cf.wuf.l, model = "direct", by="terms",
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cfl$ContainerID,
type = "free"), nperm = 999))
aov.cf.wuf.l
View(aov.cf.wuf.l)
# Calculate dbRDA
dbRDA.cs.wuf.l <- dbrda(wuf.csl ~ env.csl$Density * env.csl$Timepoint)
RsquareAdj(dbRDA.cs.wuf.l)
# permutation tests
dbRDA.cs.wuf0.l <- dbrda(wuf.csl ~ 1)
anova(dbRDA.cs.wuf0.l, dbRDA.cs.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.csl$ContainerID,
type = "free"), nperm = 999))
# by terms
aov.cs.wuf.l <- anova.cca(dbRDA.cs.wuf.l, model = "direct", by="terms",
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.csl$ContainerID,
type = "free"), nperm = 999))
aov.cs.wuf.l
View(aov.cs.wuf.l)
# Calculate dbRDA
dbRDA.cm.wuf.l <- dbrda(wuf.cml ~ env.cml$Density * env.cml$Timepoint)
RsquareAdj(dbRDA.cm.wuf.l)
# permutation tests
dbRDA.cm.wuf0.l <- dbrda(wuf.cml ~ 1)
anova(dbRDA.cm.wuf0.l, dbRDA.cm.wuf.l,
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cml$ContainerID,
type = "free"), nperm = 999))
# by terms
aov.cm.wuf.l <- anova.cca(dbRDA.cm.wuf.l, model = "direct", by="terms",
permutations = how(within = Within(type = "none"),
plots = Plots(strata = env.cml$ContainerID,
type = "free"), nperm = 999))
aov.cm.wuf.l
View(aov.cm.wuf.l)
library(phyloseq)
library(microbiome)
library(microbiomeutilities) # format_to_besthit()
library(ggpubr) # ggarrange()
library(plyr)
library(dplyr)
library(ape)
library(reshape2)
library(scales)
library(knitr)
library(ggrepel)
library(nlme)
library(lme4)
library(sciplot) # se() function
library(apeglm)
library(pheatmap)
library(picante)
library(emmeans)
library(multcomp)
library(multcompView)
library(purrr) # functions for lists
library(car) # Anova() function (for glmer)
library(ggvegan) # customize PRC plot
# colour palettes
library(viridis)
library(RColorBrewer)
sessionInfo()
library(phyloseq)
library(microbiome)
library(microbiomeutilities) # format_to_besthit()
library(ggpubr) # ggarrange()
library(plyr)
library(dplyr)
library(ape)
library(reshape2)
library(scales)
library(knitr)
library(ggrepel)
library(nlme)
library(lme4)
library(sciplot) # se() function
library(apeglm)
library(pheatmap)
library(picante)
library(emmeans)
library(multcomp)
library(multcompView)
library(purrr) # functions for lists
library(car) # Anova() function (for glmer)
library(ggvegan) # customize PRC plot
# colour palettes
library(viridis)
library(RColorBrewer)
sessionInfo()
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.pdf",
h = 175, w = 250, u = "mm")
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.eps",
h = 175, w = 250, u = "mm")
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.eps",
h = 122, w = 174, u = "mm", dpi = 1200)
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.eps",
h = 122, w = 174, u = "mm")
windowsFonts()
p.pdg.bk
p.pdg.bk <- ggplot(pd.g.emm4, aes(x = Timepoint, y = emmean,
group = interaction(Diet, Density, Type)))
p.pdg.bk <- p.pdg.bk + geom_line(size = .6, aes(linetype = Type)) +
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width = .1) +
geom_point(shape = 16, size = 3, colour = "white") +
geom_point(aes(shape = Type), size = 3, colour = "black") +
scale_shape_manual(values = c(16,1)) +
labs(x = "time (d)", y = "phylogenetic diversity",
shape = "Sample type", linetype = "Sample type") +
scale_y_continuous(limits = c(0,20), n.breaks = 6) +
facet_grid(Diet ~ Density, labeller = labs_div) +
theme_div + theme(text = element_text(family = "sans"))
p.pdg.bk
p.pdg.bk <- ggplot(pd.g.emm4, aes(x = Timepoint, y = emmean,
group = interaction(Diet, Density, Type)))
p.pdg.bk <- p.pdg.bk + geom_line(size = .6, aes(linetype = Type)) +
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width = .1) +
geom_point(shape = 16, size = 3, colour = "white") +
geom_point(aes(shape = Type), size = 3, colour = "black") +
scale_shape_manual(values = c(16,1)) +
labs(x = "time (d)", y = "phylogenetic diversity",
shape = "Sample type", linetype = "Sample type") +
scale_y_continuous(limits = c(0,20), n.breaks = 6) +
facet_grid(Diet ~ Density, labeller = labs_div) +
theme_div + theme(text = element_text(family = "serif"))
p.pdg.bk
p.pdg.bk <- ggplot(pd.g.emm4, aes(x = Timepoint, y = emmean,
group = interaction(Diet, Density, Type)))
p.pdg.bk <- p.pdg.bk + geom_line(size = .6, aes(linetype = Type)) +
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width = .1) +
geom_point(shape = 16, size = 3, colour = "white") +
geom_point(aes(shape = Type), size = 3, colour = "black") +
scale_shape_manual(values = c(16,1)) +
labs(x = "time (d)", y = "phylogenetic diversity",
shape = "Sample type", linetype = "Sample type") +
scale_y_continuous(limits = c(0,20), n.breaks = 6) +
facet_grid(Diet ~ Density, labeller = labs_div) +
theme_div + theme(text = element_text(family = "sans"))
p.pdg.bk
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.eps",
h = 122, w = 174, u = "mm")
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.eps")
p.pdg.bk <- ggplot(pd.g.emm4, aes(x = Timepoint, y = emmean,
group = interaction(Diet, Density, Type)))
p.pdg.bk <- p.pdg.bk + geom_line(size = .6, aes(linetype = Type)) +
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width = .1) +
geom_point(shape = 16, size = 3, colour = "white") +
geom_point(aes(shape = Type), size = 3, colour = "black") +
scale_shape_manual(values = c(16,1)) +
labs(x = "time (d)", y = "phylogenetic diversity",
shape = "Sample type", linetype = "Sample type") +
scale_y_continuous(limits = c(0,20), n.breaks = 6) +
facet_grid(Diet ~ Density, labeller = labs_div) +
theme_div + theme(text = element_text(family = "TT Arial"))
p.pdg.bk
p.pdg.bk <- ggplot(pd.g.emm4, aes(x = Timepoint, y = emmean,
group = interaction(Diet, Density, Type)))
p.pdg.bk <- p.pdg.bk + geom_line(size = .6, aes(linetype = Type)) +
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width = .1) +
geom_point(shape = 16, size = 3, colour = "white") +
geom_point(aes(shape = Type), size = 3, colour = "black") +
scale_shape_manual(values = c(16,1)) +
labs(x = "time (d)", y = "phylogenetic diversity",
shape = "Sample type", linetype = "Sample type") +
scale_y_continuous(limits = c(0,20), n.breaks = 6) +
facet_grid(Diet ~ Density, labeller = labs_div) +
theme_div + theme(text = element_text(family = "Arial"))
p.pdg.bk
p.pdg.bk <- ggplot(pd.g.emm4, aes(x = Timepoint, y = emmean,
group = interaction(Diet, Density, Type)))
p.pdg.bk <- p.pdg.bk + geom_line(size = .6, aes(linetype = Type)) +
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width = .1) +
geom_point(shape = 16, size = 3, colour = "white") +
geom_point(aes(shape = Type), size = 3, colour = "black") +
scale_shape_manual(values = c(16,1)) +
labs(x = "time (d)", y = "phylogenetic diversity",
shape = "Sample type", linetype = "Sample type") +
scale_y_continuous(limits = c(0,20), n.breaks = 6) +
facet_grid(Diet ~ Density, labeller = labs_div) +
theme_div + theme(text = element_text(family = "sans"))
p.pdg.bk
p.pdg.bk <- ggplot(pd.g.emm4, aes(x = Timepoint, y = emmean,
group = interaction(Diet, Density, Type)))
p.pdg.bk <- p.pdg.bk + geom_line(size = .6, aes(linetype = Type)) +
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width = .1) +
geom_point(shape = 16, size = 3, colour = "white") +
geom_point(aes(shape = Type), size = 3, colour = "black") +
scale_shape_manual(values = c(16,1)) +
labs(x = "time (d)", y = "phylogenetic diversity",
shape = "Sample type", linetype = "Sample type") +
scale_y_continuous(limits = c(0,20), n.breaks = 6) +
facet_grid(Diet ~ Density, labeller = labs_div) +
theme_div
p.pdg.bk
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.eps")
ggsave(plot= p.pdg.bk, "./figures/Diversity_Phylogenetic_genus_EMM_black.eps",
h = 7, w = 10)
ggsave(plot = pNMDS0x, "./figures/NMDS_all.eps", h = 3.5, w = 10)
ggsave(plot = pNMDS.leg0x, "./figures/NMDS_leg-all.eps", h = 4, w = 4)
ggsave(plot = pNMDS.sum.cf0, "./figures/NMDS_CF_sd-all.eps", h = 3.5, w = 10)
ggsave(plot = pNMDS.sum.cm0, "./figures/NMDS_CM_sd-all.eps", h = 3.5, w = 10)
ggsave(plot = pNMDS.sum.cs0, "./figures/NMDS_CS_sd-all.eps", h = 3.5, w = 10)
# TIFF files: used in AEM submission
ggsave(plot = pNMDS0x, "./figures/NMDS_all.tiff", h = 65, w = 174, dpi = 600)
# TIFF files: used in AEM submission
ggsave(plot = pNMDS0x, "./figures/NMDS_all.tiff", h = 65, w = 174, u = "mm", dpi = 600)
# TIFF files: used in AEM submission
ggsave(plot = pNMDS0x, "./figures/NMDS_all.tiff", h = 3.5, w = 10, u = "in", dpi = 600)
ggsave(plot = pNMDS.leg0x, "./figures/NMDS_leg-all.tiff", h = 4, w = 4, u = "in", dpi = 600)
ggsave(plot = pNMDS.sum.cf0, "./figures/NMDS_CF_sd-all.tiff", h = 3.5, w = 10, u = "in", dpi = 600)
ggsave(plot = pNMDS.sum.cm0, "./figures/NMDS_CM_sd-all.tiff", h = 3.5, w = 10, u = "in", dpi = 600)
ggsave(plot = pNMDS.sum.cs0, "./figures/NMDS_CS_sd-all.tiff", h = 3.5, w = 10, u = "in", dpi = 600)
library(phyloseq)
library(microbiome)
library(microbiomeutilities) # format_to_besthit()
library(ggpubr) # ggarrange()
library(plyr)
library(dplyr)
library(ape)
library(reshape2)
library(scales)
library(knitr)
library(ggrepel)
library(nlme)
library(lme4)
library(sciplot) # se() function
library(apeglm)
library(pheatmap)
library(picante)
library(emmeans)
library(multcomp)
library(multcompView)
library(purrr) # functions for lists
library(car) # Anova() function (for glmer)
library(ggvegan) # customize PRC plot
# colour palettes
library(viridis)
library(RColorBrewer)
sessionInfo()
View(A0)
pA0
View(patho.df)
pPatho
pPatho.all
rm(pPatho.Aci, pPatho.Bac, pPatho.Cit, pPatho.Clo, pPatho.Cor, pPatho.Enb, pPatho.Enc, pPatho.Esc, pPatho.Kle, pPatho.Pep, pPatho.Pro, pPatho.Prv, pPatho.Ser)
rm(pPatho.all)
rm(pPatho)
rm(maxPa)
rm(patho.sum,
patho.all,
patho.all2,
patho.m,
patho.low)
rm(patho.df)
rm(pathogens)
# summarize
rm(nmds.sum0, pNMDS.sum0x)
# plot only legend
rm(nmds.legend0, pNMDS0, pNMDS.leg0)
rm(pNMDS0, pNMDS0.2)
rm(pLarv.15)
# plot samples
rm(pLarv)
