#************************************************************************************************ #### Graphiques inutilisés dans le rapport de stage ------------------------------------- #************************************************************************************************ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # graphiques des distributions des concentrations des métaux ---- # Calcium en bonus ggplot(data_complet, aes(x = calcium)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#FEB37BFF", alpha = 0.7) + labs(x= "Calcium", y= "Densité", title= "Répartition des concentrations du Calcium") + stat_function(fun = dnorm, args = list(mean = mean(data_complet$calcium, na.rm = TRUE), sd = sd(data_complet$calcium, na.rm = TRUE)), color = "red", linewidth = 1) + xlim(c(0, 200)) + theme_minimal() + theme( plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Magnésium ggplot(data_complet, aes(x = magnesium)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#39558CFF", alpha = 0.7) + labs(x= "Magnésium", y= "Densité", title= "Répartition des concentrations du Magnésium") + stat_function(fun = dnorm, args = list(mean = mean(data_complet$magnesium, na.rm = TRUE), sd = sd(data_complet$magnesium, na.rm = TRUE)), color = "red", linewidth = 1) + xlim(c(0, 200)) + theme_minimal() + theme( plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Sodium ggplot(data_complet, aes(x = sodium)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#D8456CFF", alpha = 0.7) + labs(x= "Sodium", y= "Densité", title= "Répartition des concentrations du Sodium") + stat_function(fun = dnorm, args = list(mean = mean(data_complet$sodium, na.rm = TRUE), sd = sd(data_complet$sodium, na.rm = TRUE)), color = "red", linewidth = 1) + xlim(c(0, 200)) + theme_minimal() + theme( plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Plomb ggplot(data_complet, aes(x = plomb)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#21908CFF", alpha = 0.7) + labs(x= "Plomb", y= "Densité", title= "Répartition des concentrations du Plomb") + stat_function(fun = dnorm, args = list(mean = mean(data$plomb, na.rm = TRUE), sd = sd(data$plomb, na.rm = TRUE)), color = "red", linewidth = 1) + geom_vline(xintercept = 0.31, color = "tomato3", lty = "dashed") + theme_minimal() + theme( plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Nickel ggplot(data_complet, aes(x = nickel)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#B63679FF", alpha = 0.7) + labs(x= "Nickel", y= "Densité", title= "Répartition des concentrations du Nickel") + stat_function(fun = dnorm, args = list(mean = mean(data$nickel, na.rm = TRUE), sd = sd(data$nickel, na.rm = TRUE)), color = "red", linewidth = 1) + geom_vline(xintercept = 0.4, color = "tomato3", lty = "dashed") + theme_minimal() + theme( plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Cadmium ggplot(data_complet, aes(x = cadmium)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#F98C0AFF", alpha = 0.7) + labs(x= "Cadmium", y= "Densité", title= "Répartition des concentrations du Cadmium") + stat_function(fun = dnorm, args = list(mean = mean(data$cadmium, na.rm = TRUE), sd = sd(data$cadmium, na.rm = TRUE)), color = "red", linewidth = 1) + geom_vline(xintercept = 0.025, color = "tomato3", lty = "dashed") + theme_minimal() + theme( plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Graphique densité Ci avec BBAC # BBAC bbac <- data.frame( metal = c("Cadmium", "Nickel", "Plomb"), BBAC = c(0.025, 0.400, 0.310), # mg/kg PF unite = "mg/kg PF") data_long_Ci <- data_complet %>% select(cadmium, nickel, plomb) %>% pivot_longer(cols = everything(), names_to = "metal_raw", values_to = "Ci") %>% mutate(metal = case_when( metal_raw == "cadmium" ~ "Cadmium", metal_raw == "nickel" ~ "Nickel", metal_raw == "plomb" ~ "Plomb")) %>% filter(!is.na(Ci)) ggplot(data_long_Ci, aes(x = Ci, fill = metal, color = metal)) + geom_density(alpha = 0.4, linewidth = 0.8) + geom_vline(data = bbac, aes(xintercept = BBAC, color = metal), linetype = "dashed", linewidth = 1.2) + geom_text(data = bbac, aes(x = BBAC, y = Inf, label = paste0("BBAC=", BBAC)), angle = 90, vjust = -0.3, hjust = 1.2, size = 3) + facet_wrap(~ metal, scales = "free") + scale_fill_manual(values = c("Cadmium" = "#F98C0AFF", "Nickel" = "#B63679FF", "Plomb" = "#21908CFF")) + scale_color_manual(values = c("Cadmium" = "#F98C0AFF", "Nickel" = "#B63679FF", "Plomb" = "#21908CFF")) + labs(title = "Distribution des concentrations dans le gammare vs BBAC", x = "Concentration (mg/kg PF)", y = "Densite") + theme_minimal() + theme(legend.position = "none", plot.title = element_text(face = "bold", hjust = 0.5)) #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # graphiques métal en fonction du calcium # Plomb en fonction du calcium ggplot(data_complet, aes(x = calcium, y = plomb)) + geom_point(color = "#21908CFF", size = 2.5, alpha = 0.75) + geom_smooth(method = "lm", color = "#5DC863FF", linewidth = 1) + geom_line(y=0.31, linewidth = 1, color = "darkred") + labs(title = "Concentration en plomb en fonction du calcium", x = "Concentration en calcium (mg/L)", y = "Concentration en plomb (mg/kg de PF)") + theme_bw() + theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Nickel en fonction du calcium ggplot(data_complet, aes(x = calcium, y = nickel)) + geom_point(color = "#51127CFF", size = 2.5, alpha = 0.75) + geom_smooth(method = "lm", color = "#B63679FF", linewidth = 1) + geom_line(y=0.4, linewidth = 1, color = "darkred") + labs(title = "Concentration en nickel en fonction du calcium", x = "Concentration en calcium (mg/L)", y = "Concentration en nickel (mg/kg de PF)") + theme_bw() + theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Cadmium en fonction du calcium ggplot(data_complet, aes(x = calcium, y = cadmium)) + geom_point(color = "#BB3754FF", size = 2.5, alpha = 0.75) + geom_smooth(method = "lm", color = "#F98C0AFF", linewidth = 1) + geom_line(y=0.025, linewidth = 1, color = "darkred") + ylim(0, 0.4) + labs(title = "Concentration en cadmium en fonction du calcium", x = "Concentration en calcium (mg/L)", y = "Concentration en cadmium (mg/kg de PF)") + theme_bw() + theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Ratio Ci/Ceau du nickel en fonction des ions # ratio Ci/Ceau en fonction du calcium data_complet %>% filter(!is.na(nickel), !is.na(Ceau_med_ugL_Nickel), Ceau_med_ugL_Nickel > 0, !is.na(classe_calcium)) %>% mutate(ratio_Ni = nickel / Ceau_med_ugL_Nickel) %>% ggplot(aes(x = classe_calcium, y = ratio_Ni, fill = classe_calcium)) + geom_boxplot(alpha = 0.7) + scale_y_log10() + scale_fill_viridis_d() + labs(x = "Classe de calcium (mg/L)", y = "Ratio Ci/Ceau (mg/kg PF / µg/L) (échelle log)") + theme_minimal() + theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(face = "bold", hjust = 0.5)) + theme(axis.title = element_text(size = 16), axis.text = element_text(size = 16), legend.title = element_text(size = 16, face = "bold"), legend.text = element_text(size = 16)) # ratio Ci/Ceau en fonction du magnésium data_complet %>% filter(!is.na(nickel), !is.na(Ceau_med_ugL_Nickel), Ceau_med_ugL_Nickel > 0, !is.na(classe_magnesium)) %>% mutate(ratio_Ni = nickel / Ceau_med_ugL_Nickel) %>% ggplot(aes(x = classe_magnesium, y = ratio_Ni, fill = classe_magnesium)) + geom_boxplot(alpha = 0.7) + scale_y_log10() + scale_fill_viridis_d() + labs(x = "Classe de magnésium (mg/L)", y = "Ratio Ci/Ceau (mg/kg PF / µg/L) (échelle log)") + theme_minimal() + theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(face = "bold", hjust = 0.5)) + theme(axis.title = element_text(size = 16), axis.text = element_text(size = 16), legend.title = element_text(size = 16, face = "bold"), legend.text = element_text(size = 16)) # ratio Ci/Ceau en fonction du sodium data_complet %>% filter(!is.na(nickel), !is.na(Ceau_med_ugL_Nickel), Ceau_med_ugL_Nickel > 0, !is.na(classe_sodium)) %>% mutate(ratio_Ni = nickel / Ceau_med_ugL_Nickel) %>% ggplot(aes(x = classe_sodium, y = ratio_Ni, fill = classe_sodium)) + geom_boxplot(alpha = 0.7) + scale_y_log10() + scale_fill_viridis_d() + labs(x = "Classe de sodium (mg/L)", y = "Ratio Ci/Ceau (mg/kg PF / µg/L) (échelle log)") + theme_minimal() + theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(face = "bold", hjust = 0.5)) + theme(axis.title = element_text(size = 16), axis.text = element_text(size = 16), legend.title = element_text(size = 16, face = "bold"), legend.text = element_text(size = 16)) #************************************************************************************************ #### Graphiques 3D des concentrations d'ions ---------------------------------------------------- #************************************************************************************************ # enlever les NA pour pas les mettre dans le graphe data_3D <- naiades %>% filter(!is.na(calcium), !is.na(sodium), !is.na(magnesium)) plot_ly( data = data_3D, x = ~calcium, y = ~sodium, z = ~magnesium, type = "scatter3d", mode = "markers", marker = list(size = 4, color = ~calcium, colorscale = "Viridis", showscale = TRUE), text = ~code_stat, hovertemplate = paste( "Station: %{text}
", "Calcium: %{x} mg/L
", "Sodium: %{y} mg/L
", "Magnesium: %{z} mg/L") ) %>% layout(scene = list( xaxis = list(title = "Calcium (mg/L)"), yaxis = list(title = "Sodium (mg/L)"), zaxis = list(title = "Magnesium (mg/L)") ), title = "Concentrations en ions par station") #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Graphiques distributions Ceau prédite (BLM) # Cadmium ggplot(data_complet, aes(x = Ceau_Cd_ugL)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#F98C0AFF", alpha = 0.7) + labs(x= "Cadmium", y= "Densité", title= "Répartition des concentrations prédites du Cadmium") + stat_function(fun = dnorm, args = list(mean = mean(Ceau_Cd_ugL, na.rm = TRUE), sd = sd(Ceau_Cd_ugL, na.rm = TRUE)), color = "red", linewidth = 1) + geom_vline(xintercept = 0.4, color = "tomato3", lty = "dashed") + theme_minimal() + theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Nickel ggplot(data_complet, aes(x = Ceau_Ni_ugL)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#B63679FF", alpha = 0.7) + labs(x= "Nickel", y= "Densité", title= "Répartition des concentrations prédites du Nickel") + stat_function(fun = dnorm, args = list(mean = mean(Ceau_Ni_ugL, na.rm = TRUE), sd = sd(Ceau_Ni_ugL, na.rm = TRUE)), color = "red", linewidth = 1) + geom_vline(xintercept = 0.4, color = "tomato3", lty = "dashed") + theme_minimal() + theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) # Plomb ggplot(data_complet, aes(x = Ceau_Pb_ugL)) + geom_histogram(aes(y = after_stat(density)), bins = 50, fill = "#21908CFF", alpha = 0.7) + labs(x= "Plomb", y= "Densité", title= "Répartition des concentrations prédites du Plomb") + stat_function(fun = dnorm, args = list(mean = mean(Ceau_Pb_ugL, na.rm = TRUE), sd = sd(Ceau_Pb_ugL, na.rm = TRUE)), color = "red", linewidth = 1) + geom_vline(xintercept = 0.4, color = "tomato3", lty = "dashed") + theme_minimal() + theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 14), axis.title = element_text(size = 12), axis.text = element_text(size = 10)) #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Graphiques cartes: Ceau prédite (BLM) vs NQE #+++++++++++++++++++++++++++++++++++++++++ # Seuils NQE eau (µg/L) # Seuils NQE en µg/L NQE_Cd <- 0.08 NQE_Ni <- 4.0 NQE_Pb <- 1.2 # NQE Cd ajustée au calcium (CaCO3) de la station NQE_Cd_calcique <- function(calcium_mgL) { durete <- calcium_mgL * 2.5 # conversion Ca en CaCO3 pour les classes NQE case_when( durete < 40 ~ 0.08, durete >= 40 & durete < 50 ~ 0.09, durete >= 50 & durete < 100 ~ 0.15, durete >= 100 ~ 0.25, TRUE ~ NA_real_) } # on ajoute une colonne dans data_complet pour le seuil NQE data_complet <- data_complet %>% mutate( NQE_Cd_stat = NQE_Cd_calcique(calcium), classe_Ceau_Cd = case_when( is.na(Ceau_Cd_ugL) | is.na(NQE_Cd_stat) ~ NA_character_, Ceau_Cd_ugL <= NQE_Cd_stat ~ "En dessous de la NQE", Ceau_Cd_ugL > NQE_Cd_stat ~ "Au dessus de la NQE" ) %>% factor(levels = c("En dessous de la NQE", "Au dessus de la NQE"))) # Créer les classes pour Ni et Pb data_complet <- data_complet %>% mutate( classe_Ceau_Ni = cut(Ceau_Ni_ugL, breaks = c(0, NQE_Ni, Inf), labels = c("En dessous de la NQE", "Au dessus de la NQE"), include.lowest = TRUE), classe_Ceau_Pb = cut(Ceau_Pb_ugL, breaks = c(0, NQE_Pb, Inf), labels = c("En dessous de la NQE", "Au dessus de la NQE"), include.lowest = TRUE)) # Nombre de stations dans chaque cas + nombre NA table(data_complet$classe_Ceau_Cd, useNA = "always") table(data_complet$classe_Ceau_Ni, useNA = "always") table(data_complet$classe_Ceau_Pb, useNA = "always") # Cadmium ggplot() + geom_polygon(data = france, aes(x = long, y = lat, group = group), fill = "grey91", color = "white") + geom_point(data = data_complet %>% filter(!is.na(classe_Ceau_Cd), !is.na(longitude)) %>% arrange(classe_Ceau_Cd), aes(x = longitude, y = latitude, color = classe_Ceau_Cd), size = 3) + scale_color_manual(values = c("En dessous de la NQE" = "#F98C0AFF", "Au dessus de la NQE" = "tomato4"), name = "Cadmium vs NQE") + annotate("text", y = 51.5, x = 3, label = "bold(`Cadmium prédit vs NQE (ajustée aux niveaux de calcium)`)", size = 5, parse = TRUE) + theme_void() + theme(legend.position = "right") # Nickel ggplot() + geom_polygon(data = france, aes(x = long, y = lat, group = group), fill = "grey91", color = "white") + geom_point(data = data_complet %>% filter(!is.na(classe_Ceau_Ni), !is.na(longitude)) %>% arrange(classe_Ceau_Ni), aes(x = longitude, y = latitude, color = classe_Ceau_Ni), size = 3) + scale_color_manual(values = c("En dessous de la NQE" = "#B63679FF", "Au dessus de la NQE" = "tomato4"), name = "Nickel (µg/L)") + annotate("text", y = 51.5, x = 3, label = "bold(`Nickel prédit vs NQE`)", size = 6, parse = TRUE) + theme_void() + theme(legend.position = "right") # Plomb ggplot() + geom_polygon(data = france, aes(x = long, y = lat, group = group), fill = "grey91", color = "white") + geom_point(data = data_complet %>% filter(!is.na(classe_Ceau_Pb), !is.na(longitude)) %>% arrange(classe_Ceau_Pb), aes(x = longitude, y = latitude, color = classe_Ceau_Pb), size = 3) + scale_color_manual(values = c("En dessous de la NQE" = "#21908CFF", "Au dessus de la NQE" = "tomato4"), name = "Plomb (µg/L)") + annotate("text", y = 51.5, x = 3, label = "bold(`Plomb prédit vs NQE`)", size = 6, parse = TRUE) + theme_void() + theme(legend.position = "right") #************************************************************************************************ #### Comparaison Ceau prédite (BLM) vs Ceau mesurée (Naiades) ---------------------------------- #************************************************************************************************ # Nickel data_complet %>% filter(!is.na(Ceau_Ni_ugL), !is.na(Ceau_med_ugL_Nickel)) %>% ggplot(aes(x = Ceau_med_ugL_Nickel, y = Ceau_Ni_ugL)) + geom_point(color = "#B63679FF", size = 3, alpha = 0.7) + geom_abline(slope = 1, intercept = 0, # droite 1:1 linetype = "dashed", color = "grey40") + labs(title = "Nickel: concentration prédite (BLM) vs mesurée dans l'eau", x = "Ceau mesurée Naiades (µg/L)", y = "Ceau prédite BLM (µg/L)") + theme_minimal() + theme(plot.title = element_text(face = "bold", hjust = 0.5)) # Plomb data_complet %>% filter(!is.na(Ceau_Pb_ugL), !is.na(Ceau_med_ugL_Plomb)) %>% ggplot(aes(x = Ceau_med_ugL_Plomb, y = Ceau_Pb_ugL)) + geom_point(color = "#21908CFF", size = 3, alpha = 0.7) + geom_abline(slope = 1, intercept = 0, # droite 1:1 linetype = "dashed", color = "grey40") + labs(title = "Plomb: concentration prédite (BLM) vs mesurée dans l'eau", x = "Ceau mesurée Naiades (µg/L)", y = "Ceau prédite BLM (µg/L)") + xlim(c(0,1)) + ylim(c(0, 0.02)) + theme_minimal() + theme(plot.title = element_text(face = "bold", hjust = 0.5)) #************************************************************************************************ #### Modèle TK (comparaison avec TK-BLM) ------------------------------------------------------- #************************************************************************************************ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Graphiques comparaison prédite TK vs réelle # Nickel data_complet %>% filter(!is.na(Ceau_Ni_TK_ugL), !is.na(Ceau_med_ugL_Nickel), !is.infinite(Ceau_Ni_TK_ugL), Ceau_Ni_TK_ugL > 0) %>% ggplot(aes(x = Ceau_med_ugL_Nickel, y = Ceau_Ni_TK_ugL)) + geom_point(color = "#B63679FF", size = 2.5, alpha = 0.6) + geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "grey40") + geom_hline(yintercept = 4.0, color = "red", linetype = "dotted", linewidth = 0.8) + annotate("text", x = Inf, y = 4.0, label = "NQE = 4 µg/L", color = "red", hjust = 1.1, vjust = -0.3, size = 3) + labs(title = "Nickel : Ceau prédite (TK) vs mesurée (Naiades)", x = "Ceau mesurée Naiades (µg/L)", y = "Ceau prédite TK (µg/L)") + theme_minimal() + theme(plot.title = element_text(face = "bold", hjust = 0.5)) # Plomb data_complet %>% filter(!is.na(Ceau_Pb_TK_ugL), !is.na(Ceau_med_ugL_Plomb), !is.infinite(Ceau_Pb_TK_ugL), Ceau_Pb_TK_ugL > 0) %>% ggplot(aes(x = Ceau_med_ugL_Plomb, y = Ceau_Pb_TK_ugL)) + geom_point(color = "#21908CFF", size = 2.5, alpha = 0.6) + geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "grey40") + geom_hline(yintercept = 1.2, color = "red", linetype = "dotted", linewidth = 0.8) + annotate("text", x = Inf, y = 1.2, label = "NQE = 1.2 µg/L", color = "red", hjust = 1.1, vjust = -0.3, size = 3) + labs(title = "Plomb : Ceau prédite (TK) vs mesurée (Naiades)", x = "Ceau mesurée Naiades (µg/L)", y = "Ceau prédite TK (µg/L)") + theme_minimal() + theme(plot.title = element_text(face = "bold", hjust = 0.5))