Skip to content
Snippets Groups Projects
Commit 1c3b3c94 authored by Daniel.Kalioudjoglou's avatar Daniel.Kalioudjoglou
Browse files

Merge branch '68-revoir-le-graph_3_4-chapitre-4-qui-a-des-valeurs-negatives' into 'dev'

modification de creer_graphe_3_4.R pour remplacer les valeurs négatives par un...

Closes #68

See merge request dreal-datalab/propre.artificialisation!45
parents 67a4dcc1 1a042a57
No related branches found
No related tags found
2 merge requests!65maj_avant_transfert_vers_gitlabforge,!45modification de creer_graphe_3_4.R pour remplacer les valeurs négatives par un...
Pipeline #185406 failed
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = NULL, code_reg = NULL){ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = NULL, code_reg = NULL){
attempt::stop_if(millesime_stock_artif, is.null, msg = "millesime_stock_artif n'est pas renseign\u00e9") attempt::stop_if(millesime_stock_artif, is.null, msg = "millesime_stock_artif n\'est pas renseign\u00e9")
attempt::stop_if_not(millesime_stock_artif, is.numeric, msg = "millesime_stock_artif n'est pas un nombre") attempt::stop_if_not(millesime_stock_artif, is.numeric, msg = "millesime_stock_artif n\'est pas un nombre")
attempt::stop_if(millesime_population, is.null, msg = "millesime_population n'est pas renseign\u00e9") attempt::stop_if(millesime_population, is.null, msg = "millesime_population n\'est pas renseign\u00e9")
attempt::stop_if_not(millesime_population, is.numeric, msg = "millesime_population n'est pas un nombre") attempt::stop_if_not(millesime_population, is.numeric, msg = "millesime_population n\'est pas un nombre")
attempt::stop_if(code_reg, is.null, msg = "code_reg n'est pas renseign\u00e9") attempt::stop_if(code_reg, is.null, msg = "code_reg n\'est pas renseign\u00e9")
attempt::stop_if_not(code_reg, ~ .x %in% levels(COGiter::regions$REG), msg = "code_reg n'est pas un code r\u00e9gion valide") attempt::stop_if_not(code_reg, ~ .x %in% levels(COGiter::regions$REG), msg = "code_reg n\'est pas un code r\u00e9gion valide")
# # calcul des millesimes utilises # # calcul des millesimes utilises
millesime_debut <- 2016 millesime_debut <- 2016
...@@ -89,7 +89,7 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = ...@@ -89,7 +89,7 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population =
dplyr::left_join(flux) %>% dplyr::left_join(flux) %>%
dplyr::left_join(evol_popul) %>% dplyr::left_join(evol_popul) %>%
dplyr::left_join(popul_debut) %>% dplyr::left_join(popul_debut) %>%
dplyr::mutate(Zone=as.factor(.data$Zone)) %>% dplyr::mutate(Zone = as.factor(.data$Zone)) %>%
dplyr::mutate(surf_artif_par_hab_an_x=.data$stock_depart / .data$population_debut *10000 ) %>% dplyr::mutate(surf_artif_par_hab_an_x=.data$stock_depart / .data$population_debut *10000 ) %>%
dplyr::mutate(surf_artif_par_nouv_hab_entre_x_y =.data$flux_artificialisation / .data$evolution_population *10000) %>% dplyr::mutate(surf_artif_par_nouv_hab_entre_x_y =.data$flux_artificialisation / .data$evolution_population *10000) %>%
dplyr::select (.data$TypeZone,.data$Zone,.data$surf_artif_par_hab_an_x,.data$surf_artif_par_nouv_hab_entre_x_y) %>% dplyr::select (.data$TypeZone,.data$Zone,.data$surf_artif_par_hab_an_x,.data$surf_artif_par_nouv_hab_entre_x_y) %>%
...@@ -97,26 +97,31 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = ...@@ -97,26 +97,31 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population =
dplyr::arrange(desc(.data$TypeZone),desc(.data$Zone)) %>% dplyr::arrange(desc(.data$TypeZone),desc(.data$Zone)) %>%
dplyr::mutate(variable=forcats::fct_relevel(.data$variable,"surf_artif_par_nouv_hab_entre_x_y","surf_artif_par_hab_an_x")) %>% dplyr::mutate(variable=forcats::fct_relevel(.data$variable,"surf_artif_par_nouv_hab_entre_x_y","surf_artif_par_hab_an_x")) %>%
dplyr::mutate(Zone = forcats::fct_drop(.data$Zone) %>% dplyr::mutate(Zone = forcats::fct_drop(.data$Zone) %>%
forcats::fct_inorder()) forcats::fct_inorder()) %>%
dplyr::mutate(valeur = ifelse(.data$valeur<0, 0, valeur))
# creation du graphique # creation du graphique
valeur_max_graphique <- max(data$valeur,na.rm=T)+500 valeur_max_graphique <- max(data$valeur,na.rm=T)+500
graph_3_4 <- data %>% ggplot2::ggplot(ggplot2::aes(x=.data$Zone,y=.data$valeur,fill=.data$variable), width = 0.9) + graph_3_4 <- data %>%
ggplot2::geom_bar(stat="identity",position = ggplot2::position_dodge())+ ggplot2::ggplot(ggplot2::aes(x = .data$Zone, y = .data$valeur,fill = .data$variable), width = 0.9) +
ggplot2::coord_flip() + ggplot2::geom_bar(stat = "identity", position = ggplot2::position_dodge()) +
ggplot2::geom_text(ggplot2::aes(label=format(round(.data$valeur,0), big.mark = " "),color = .data$variable),position= ggplot2::position_dodge(width=1), hjust=-0.1)+ ggplot2::coord_flip() +
ggplot2::scale_fill_manual(values = c("#82534b","#FF8D7E")) + ggplot2::geom_text(ggplot2::aes(label = ifelse(.data$valeur>0, format(round(.data$valeur,0), big.mark = " "), "population en baisse"),
ggplot2::scale_color_manual(values = c("#82534b","#FF8D7E")) + color = .data$variable),
position = ggplot2::position_dodge(width = 1),
hjust = -0.1) +
ggplot2::scale_color_manual(values = gouvdown::gouv_palettes$pal_gouv_h[1:2]) +
ggplot2::scale_fill_manual(values = gouvdown::gouv_palettes$pal_gouv_h[1:2]) +
ggplot2::labs( ggplot2::labs(
title = glue::glue("Surfaces cadastr\u00e9es artificialis\u00e9es (m2)", width = 60), title = glue::glue("Surfaces cadastr\u00e9es artificialis\u00e9es (m\u00b2)", width = 60),
subtitle = glue::glue("<span style = 'color:#FF8D7E'>par habitant pr\u00e9sent en {millesime_debut_population}</span> et <span style = 'color:#82534b'>par nouvel habitant entre {millesime_debut_population} et {millesime_fin_population}</span> "), subtitle = glue::glue("<span style = \'color:#FF8D7E\'>par habitant pr\u00e9sent en {millesime_debut_population}</span> et <span style = \'color:#D6857B\'>par nouvel habitant entre {millesime_debut_population} et {millesime_fin_population}</span> "),
x = "", y = "", x = "",
y = "",
fill = "", fill = "",
caption = glue::glue("Source : DGFip Majic/Cerema Fichiers fonciers - Insee - {millesime_stock_artif}") caption = glue::glue("Source : Cerema Fichiers fonciers {millesime_stock_artif} - Insee Population l\u00e9gale {millesime_population} ")
) + ) +
ggplot2::scale_y_continuous( ggplot2::scale_y_continuous(
# limits = c(0, max(data$valeur) +500),
labels = scales::label_number(big.mark = " ", decimal.mark = ",") labels = scales::label_number(big.mark = " ", decimal.mark = ",")
) + ) +
ggplot2::theme( ggplot2::theme(
......
...@@ -11,7 +11,7 @@ params: ...@@ -11,7 +11,7 @@ params:
millesime_obs_artif: 2020 millesime_obs_artif: 2020
millesime_etalement_urbain: 2020 millesime_etalement_urbain: 2020
millesime_obs_artif_gk3: 2019 millesime_obs_artif_gk3: 2019
millesime_population: 2018 millesime_population: 2019
millesime_stock_artif: 2020 millesime_stock_artif: 2020
code_reg: 52 code_reg: 52
title: "L'artificialisation des sols en `r mapfactory::get_nom_reg(params$code_reg)` en `r params$millesime_obs_artif`" title: "L'artificialisation des sols en `r mapfactory::get_nom_reg(params$code_reg)` en `r params$millesime_obs_artif`"
...@@ -156,8 +156,8 @@ creer_graphe_3_3(millesime_stock_artif = params$millesime_stock_artif, ...@@ -156,8 +156,8 @@ creer_graphe_3_3(millesime_stock_artif = params$millesime_stock_artif,
## 4 - En Loire-Atlantique, un nouvel habitant consommera moins d'espace que la population en place. ## 4 - En Loire-Atlantique, un nouvel habitant consommera moins d'espace que la population en place.
```{r graph surfaces artificialisees par habitant,fig.width=10,fig.height=7} ```{r graph surfaces artificialisees par habitant,fig.width=9,fig.height=7}
creer_graphe_3_4(millesime_stock_artif = params$millesime_obs_artif_gk3, creer_graphe_3_4(millesime_stock_artif = params$millesime_stock_artif,
millesime_population = params$millesime_population, millesime_population = params$millesime_population,
code_reg = params$code_reg) code_reg = params$code_reg)
``` ```
......
...@@ -65,7 +65,5 @@ creer_graphe_3_3(millesime_stock_artif = 2020, ...@@ -65,7 +65,5 @@ creer_graphe_3_3(millesime_stock_artif = 2020,
La fonction `creer_graphe_3_4()` produit le graphique des surfaces artificialisées pour un nouvel habitant par département. La fonction `creer_graphe_3_4()` produit le graphique des surfaces artificialisées pour un nouvel habitant par département.
```{r creer_graphe_3_4, fig.height=5,fig.width=8} ```{r creer_graphe_3_4, fig.height=5,fig.width=8}
creer_graphe_3_4(millesime_stock_artif = 2020, creer_graphe_3_4(millesime_stock_artif = 2020, millesime_population = 2019, code_reg = 52)
millesime_population = 2019,
code_reg = 52)
``` ```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment