library(tidyverse)
library(mgcv)
library(ggplot2)
library(ggeffects)
library(gridExtra)
load("data/2021/clean_dataset/data_mtz_2021_V02.RData")
set.seed(2224)
gam_model <- gam(
(Densite_p) ~
s(Depth2_m, bs = "cr", k = 15) +
s(Temp_C, bs = "cr", k = 15) +
s(pH, bs = "cr", k = 15) +
s(FLOR_mg.m3, bs = "cr", k = 15) +
s(TRB2_FTU, bs = "cr", k = 15) +
s(Sal_PSU, bs = "cr", k = 15) +
s(PicoCyano_PE_ml, bs = "cr", k = 15)+
s(NanoCyano_PE_ml, bs = "cr", k = 15)+
s(PicoCyano_PC_ml, bs = "cr", k = 15)+
s(NanoCyano_PC_ml, bs = "cr", k = 15)+
s(PicoEuca_ml, bs = "cr", k = 15)+
s(NanoEuca_ml, bs = "cr", k = 15)+
s(Bact_LNA_ml, bs = "cr", k = 15)+
s(Bact_HNA_ml, bs = "cr", k = 15)+
# s(OXYM_µM) +
# s(SIGM_kg.m3, bs = "cr") +
# s(SPVA_m3.kg, bs = "cr", k = 9) +
s(Leg, bs = "re") +
# s(TAXONS, bs = "re") +
s(Salinity_zone, bs = "re") +
s(Stade_gp, bs = "re"),
family = gaussian(),
method = "REML",
# gamma = 1.4,
data = mtz.2021.df %>%
dplyr::filter(TAXONS == "Eurytemora affinis")
)
summary(gam_model)
# Effets partiels
plot(gam_model, pages = 1, residuals = TRUE, all.terms = TRUE, shade = TRUE, shade.col = "lightblue")
performance::model_performance(gam_model)
performance::check_collinearity(gam_model)
# gam.check(gam_model)
# Effets prédits
p1 <- ggplot(ggpredict(gam_model, terms = "Depth2_m"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet de la Profondeur sur la Densité",
x = "Profondeur (m)", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p2 <- ggplot(ggpredict(gam_model, terms = "Temp_C"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet de la Température sur la Densité",
x = "Température (°C)", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p3 <- ggplot(ggpredict(gam_model, terms = "pH"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet du pH sur la Densité",
x = "pH", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p4 <- ggplot(ggpredict(gam_model, terms = "FLOR_mg.m3"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet de la chlorophylle a sur la Densité",
x = "Fluorescence (mg.m3)", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p5 <- ggplot(ggpredict(gam_model, terms = "TRB2_FTU"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet de la turbidité a sur la Densité",
x = "Turbidité", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p6 <- ggplot(ggpredict(gam_model, terms = "Sal_PSU"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet de la salinité sur la Densité",
x = "Salinité", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p7 <- ggplot(ggpredict(gam_model, terms = "PicoCyano_PE_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des pico cyanobactéries PE sur la Densité",
x = "Pico cyanobactéries PE par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p8 <- ggplot(ggpredict(gam_model, terms = "NanoCyano_PE_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des nano cyanobactéries PE sur la Densité",
x = "Nano cyanobactéries PE par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p9 <- ggplot(ggpredict(gam_model, terms = "PicoCyano_PC_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des pico cyanobactéries PC sur la Densité",
x = "Pico cyanobactéries PC par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p10 <- ggplot(ggpredict(gam_model, terms = "NanoCyano_PC_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des nano cyanobactéries PC sur la Densité",
x = "Nano cyanobactéries PC par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p11 <- ggplot(ggpredict(gam_model, terms = "PicoEuca_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des pico eucaryotes sur la Densité",
x = "Pico eucaryotes par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p12 <- ggplot(ggpredict(gam_model, terms = "NanoEuca_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des nano eucaryotes sur la Densité",
x = "Nano eucaryotes par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p13 <- ggplot(ggpredict(gam_model, terms = "Bact_LNA_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des bactéries LNA sur la Densité",
x = "Bactéries LNA par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
p14 <- ggplot(ggpredict(gam_model, terms = "Bact_HNA_ml"),
aes((x), predicted)) +
geom_line(color = "forestgreen") +
geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.25, fill = "lightblue") +
labs(title = "Effet des bactéries HNA sur la Densité",
x = "Bactéries HNA par mL", y = "Densité prédite") +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
)
# Boxplot de la densité par zone de salinité et taxon
pdensite <- ggplot(mtz.2021.df %>%
dplyr::filter(TAXONS == "Eurytemora affinis"),
aes(x = Salinity_zone, y = (Densite_p), fill = Stade_gp)) +
geom_bar(stat = "identity", position = "stack") +
labs(title = latex2exp::TeX("Densité par Zone de Salinité pour $\\textit{Eurytemora\\ affinis\\ CNA}$ à chaque Leg"),
x = "Zone de Salinité",
y = latex2exp::TeX("$Densité\\ (Abondance.m^{-3})$") ) +
# y = latex2exp::TeX("$\\sqrt{Densité}$") ) +
theme_bw() +
theme(
panel.background = element_rect(fill='transparent'),
plot.background = element_rect(fill='transparent', color=NA),
legend.background = element_rect(fill='transparent'),
legend.box.background = element_rect(fill='transparent')
) +
scale_fill_viridis_d(option = "G", name = "Stades de développement", direction = 1, end = 0.3, begin = 0.8)+
facet_wrap(~Leg, scale = "fixed")+
coord_flip()
# Affichage des graphiques
grid.arrange(p1 , p2 , p3 ,
p4 , p5 , p6 ,
p7 , p8 , p9 ,
p10, p11, p12,
p13, p14,
pdensite , ncol = 5, nrow = 3)