library(tidyverse)
library(wesanderson) # Palette de couleur
library(aspe) # Traitement de la base aspe
library(gratia)
library(patchwork)
library(ggh4x)
load(file = "../processed_data/selection_especes.rda")
load(file = "../processed_data/selection_pop_ope.rda")
load(file = "../processed_data/donnees_densite_eff_abs.rda")
load(file = "../processed_data/selection_pop_ope_carte.rda")
load(file = "../processed_data/pre_traitements_donnees_especes.rda")
rdata_tables <- misc_nom_dernier_fichier(
repertoire = "../../../../Liste_rouge_BFC/raw_data",
pattern = "^tables")
load(rdata_tables) # Chargement des données
# Ajout du protocole, de la surface d'opération et de la date
ope_effectif_glm <- ope_effectif_absences %>%
mef_ajouter_type_protocole() %>%
mef_ajouter_surf_calc() %>%
mef_ajouter_ope_date() %>%
select(ope_id,
stade,
ope_surface_calculee,
esp_code_alternatif,
indicateur,
valeur,
ope_date,
pro_libelle,
annee)
ope_effectif_glm <- ope_effectif_glm %>% #Ajout des pop_id dans le dataframe
left_join(y=operation %>%
select(ope_id,
pop_id= ope_pop_id)) %>%
mutate(pop_id = as.factor(pop_id))
ope_effectif_glm <- ope_effectif_glm %>% # Ajout de la date de pĂªche codĂ©e de 1 Ă 365
mutate(julian = lubridate::yday(ope_date)) %>%
ungroup() %>%
rename(espece = esp_code_alternatif) %>%
mutate(stade = as.factor(stade))
# Creation du df par especes avec effectif total
total_valeur_esp_abs <- ope_effectif_glm %>%
group_by(annee, espece, indicateur) %>%
summarise(effectif_total = sum(valeur), .groups = "drop") %>%
select(espece, annee, effectif_total, indicateur)
# preparer la table pour jointure
ope_selection <- ope_selection %>%
dplyr::select(ope_id, pop_id, sta_id)
esp_ope_selection_graph <- esp_ope_selection %>%
mef_ajouter_type_protocole() %>%
left_join(ope_selection, by = "ope_id") %>%
rename(valeur = lop_effectif, annee = annee.x) %>%
mutate(
valeur = as.numeric(valeur) ,
annee = as.numeric(annee),
ope_surface_calculee = as.numeric(ope_surface_calculee) ,
pro_libelle = as.factor(pro_libelle),
pop_id = as.factor(pop_id),
sta_id = as.factor(sta_id),
indicateur = "effectif_total"
) %>%
select(
ope_id,
valeur,
esp_code_alternatif,
annee,
ope_surface_calculee,
pro_libelle,
pop_id,
sta_id,
indicateur
)
# Creation du df par especes avec effectif total
total_valeur_esp <- esp_ope_selection_graph %>%
group_by(annee, esp_code_alternatif, indicateur) %>%
summarise(effectif_total = sum(valeur), .groups = "drop") %>%
select(esp_code_alternatif, annee, effectif_total, indicateur)
effectif_total_esp_abs <- ggplot(total_valeur_esp_abs, aes(x = annee, y = effectif_total)) +
facet_wrap2(
espece ~ indicateur,
ncol = 3,
scales = "free_y",
axes = "all",
trim_blank = T
) +
geom_point(shape = 21, size = 2) +
geom_line(linetype = 3, linewidth = 0.5) +
labs(x = "Années", y = "Effectif total") +
geom_smooth(method = "lm", color = "darkred") +
# geom_smooth(method = "loess",
# se = F,
# color = "darkred") + # Add loess trend lines
theme(
strip.background = element_rect(color = "grey85", fill = "grey85"),
legend.position = "bottom",
panel.background = element_rect(fill = "grey95"),
panel.grid.major = element_line(color = "#faffff", size = 0.1),
panel.grid.minor = element_line(color = "#faffff")
)
effectif_total_esp_abs
effectif_total_esp_abs <- ggplot(total_valeur_esp_abs, aes(x = annee, y = effectif_total)) +
facet_wrap2(
espece ~ indicateur,
ncol = 3,
scales = "free_y",
axes = "all",
trim_blank = T
) +
geom_point(shape = 21, size = 2) +
geom_line(linetype = 3, linewidth = 0.5) +
labs(x = "Années", y = "Effectif total") +
# geom_smooth(method = "lm", color = "darkred") +
geom_smooth(method = "loess",
se = F,
color = "darkred") + # Add loess trend lines
theme(
strip.background = element_rect(color = "grey85", fill = "grey85"),
legend.position = "bottom",
panel.background = element_rect(fill = "grey95"),
panel.grid.major = element_line(color = "#faffff", size = 0.1),
panel.grid.minor = element_line(color = "#faffff")
)
effectif_total_esp_abs
## Df avec les effectif des espèces, non traité par classes d’ages
# Creation du graph
effectif_total_esp <- ggplot(total_valeur_esp, aes(x = annee, y = effectif_total)) +
facet_wrap2(
esp_code_alternatif ~ indicateur,
ncol = 3,
scales = "free_y",
axes = "all",
trim_blank = T
) +
geom_point(shape = 21, size = 2) +
geom_line(linetype = 3, linewidth = 0.5) +
labs(x = "Années", y = "Effectif total") +
# geom_smooth(method = "loess",
# se = F,
# color = "darkred") + # Add loess trend lines
geom_smooth(method = "lm", color = "darkred") +
theme(
strip.background = element_rect(color = "grey85", fill = "grey85"),
legend.position = "bottom",
panel.background = element_rect(fill = "grey95"),
panel.grid.major = element_line(color = "#faffff", size = 0.1),
panel.grid.minor = element_line(color = "#faffff")
)
effectif_total_esp
# Creation du graph
effectif_total_esp <- ggplot(total_valeur_esp, aes(x = annee, y = effectif_total)) +
facet_wrap2(
esp_code_alternatif ~ indicateur,
ncol = 3,
scales = "free_y",
axes = "all",
trim_blank = T
) +
geom_point(shape = 21, size = 2) +
geom_line(linetype = 3, linewidth = 0.5) +
labs(x = "Années", y = "Effectif total") +
geom_smooth(method = "loess",
se = F,
color = "darkred") + # Add loess trend lines
# geom_smooth(method = "lm", color = "darkred") +
theme(
strip.background = element_rect(color = "grey85", fill = "grey85"),
legend.position = "bottom",
panel.background = element_rect(fill = "grey95"),
panel.grid.major = element_line(color = "#faffff", size = 0.1),
panel.grid.minor = element_line(color = "#faffff")
)
effectif_total_esp