diff --git a/DESCRIPTION b/DESCRIPTION index 6c4c1d7985cf0ca2892b89ac0d5695c3cb606252..53da080c34058e4156ac775d094f40ea8b699080 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,8 +38,7 @@ Imports: stringr, tidyr, tricky, - utils, - sf + utils Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index 624b64aa832500e780fc2f4e03ead4db54fc29d6..2e51793684b18b8ec8c703d312b7e181a1eedd13 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(creer_carte_3_2) export(creer_graphe_1_1) export(creer_graphe_1_4) export(creer_graphe_1_5) +export(creer_graphe_2_3) export(creer_graphe_2_4) export(format_fr_pct) importFrom(attempt,stop_if_not) @@ -44,6 +45,7 @@ importFrom(ggplot2,geom_sf) importFrom(ggplot2,geom_text) importFrom(ggplot2,ggplot) importFrom(ggplot2,labs) +importFrom(ggplot2,position_dodge) importFrom(ggplot2,scale_fill_manual) importFrom(ggplot2,scale_size_area) importFrom(ggplot2,scale_x_discrete) diff --git a/R/creer_graphe_2_3.R b/R/creer_graphe_2_3.R new file mode 100644 index 0000000000000000000000000000000000000000..00b98fefa57baffa7182593de749cd9b90a1d55f --- /dev/null +++ b/R/creer_graphe_2_3.R @@ -0,0 +1,58 @@ +#' Creation du graphique du taux d'evolution 2009/19 (%) de l'artificialisation cadastree des differentes regions. +#' @description Graphique du taux d'evolution 2009/19 (%) de l'artificialisation cadastree des differentes regions. +#' +#' @param millesime_obs_artif_gk3 une année parmi les millesimes sélectionnables par l'utilisateur, au format numerique. +#' +#' @return Un diagramme en barres +#' +#' @importFrom dplyr mutate filter select group_by case_when +#' @importFrom forcats fct_reorder +#' @importFrom ggplot2 ggplot aes geom_bar geom_text position_dodge coord_flip labs theme element_text scale_y_continuous +#' @importFrom glue glue +#' @importFrom scales number_format +#' +#' @export +#' +#' @examples +#' creer_graphe_2_3(millesime_obs_artif_gk3=2019) + +creer_graphe_2_3 <- function(millesime_obs_artif_gk3){ + + # Creation de la table utile a la production du graphique + data <- observatoire_artificialisation_gk3 %>% + dplyr::mutate(date=year(.data$date)) %>% + dplyr::filter(.data$TypeZone == "R\u00e9gions", + !(.data$CodeZone %in% c("01","02","03","04","06")), + .data$date == millesime_obs_artif_gk3 | .data$date == millesime_obs_artif_gk3 - 9) %>% + dplyr::select (-.data$surface_naf) %>% + dplyr::group_by(.data$TypeZone,.data$Zone,.data$CodeZone) %>% + summarise(evolution=round((sum(.data$surface_artificialisee[which(date==2019)],na.rm=T) - sum(.data$surface_artificialisee[which(date==2010)],na.rm=T))/10000,0)) %>% + dplyr::mutate(couleur_barre = dplyr::case_when( + .data$CodeZone=="52"~ 1, + TRUE ~ 0)) + + valeur_max <- max(data$evolution,na.rm=T) + millesime_debut <- millesime_obs_artif_gk3 - 9 + + graph_2_3<-data %>% + ggplot2::ggplot(ggplot2::aes(x=forcats::fct_reorder(.data$Zone,.data$evolution,.desc=F), ymax=valeur_max+5000, y=.data$evolution,fill=.data$couleur_barre)) + + ggplot2::geom_bar(stat="identity")+ + ggplot2::geom_text(ggplot2::aes(y=.data$evolution , + label=.data$evolution, + color = .data$couleur_barre + ), + position= ggplot2::position_dodge(width=1), + vjust=0.5, + hjust=-0.5, + size=3) + + ggplot2::coord_flip(expand = FALSE) + + ggplot2::labs(title=glue::glue("\u00e9volution {millesime_debut} - {millesime_obs_artif_gk3} en hectares\nde l'artificialisation cadastr\u00e9e par r\u00e9gion"), + subtitle="",x="",y="", + fill="", + caption = glue::glue("Source : Observatoire artificialisation {millesime_obs_artif_gk3}"))+ + ggplot2::theme(axis.text.x = ggplot2::element_text(), legend.position = "none") + + ggplot2::scale_y_continuous(labels = scales::number_format(suffix = "", accuracy = 1)) + + return(graph_2_3) + +} diff --git a/R/data.R b/R/data.R index 73a3290c9c8da2e148e8b48569bade691c5512a6..577f68ab51cadf805babc307449fd2fa47086d5a 100644 --- a/R/data.R +++ b/R/data.R @@ -73,3 +73,18 @@ #' } #' @source \url{https://agreste.agriculture.gouv.fr/agreste-web/disaron/W0020/detail/} "etalement_urbain" + +#' Table contenant les différents indicateurs de la source observatoire_artificialisation_gk3 utiles pour la publication. +#' +#' @encoding UTF-8 +#' @format Table de 363090 lignes et 6 colonnes: +#' \describe{ +#' \item{TypeZone}{Type de territoire} +#' \item{CodeZone}{Code du territoire} +#' \item{Zone}{Libellé du territoire} +#' \item{date}{Millésime de la source} +#' \item{surface_artificialisee}{surface artificialisee} +#' \item{surface_naf}{surface naturelle agricole et forestiere} +#' } +#' @source \url{https://agreste.agriculture.gouv.fr/agreste-web/disaron/W0020/detail/} +"observatoire_artificialisation_gk3" diff --git a/R/globals.R b/R/globals.R index 4fe0d75bce6567c3279d7e4f49545e635cad43d9..714b0a4642fd247478c8673972fb75d8bfb62780 100644 --- a/R/globals.R +++ b/R/globals.R @@ -1,4 +1,4 @@ utils::globalVariables( - c("teruti","result","observatoire_artificialisation",".data","variable", - "valeur","etalement_urbain") + c("teruti","result","observatoire_artificialisation",".data","variable",".", + "valeur","etalement_urbain","observatoire_artificialisation_gk3") ) diff --git a/data-raw/dataprep.R b/data-raw/dataprep.R index 88bfa8c53d3901a9d6f83b3d5ffb5cba24f53aa8..e142ca8bdd0fa8dd1a84439e6638bb7ff56bf93e 100644 --- a/data-raw/dataprep.R +++ b/data-raw/dataprep.R @@ -64,6 +64,9 @@ observatoire_artificialisation<-dbReadTable(con_datamart, etalement_urbain<-dbReadTable(con_datamart, c("portrait_territoires","indicateur_etalement_urbain")) +# chargement donnees observatoire artificialisation Geokit3 depuis SGBD +observatoire_artificialisation_gk3<-dbReadTable(con_datamart, + c("portrait_territoires","indicateur_observatoire_artificialisation_geokit3")) # chargement des tables cogifiées d'indicateurs territoriaux load("extdata/cogifiee_chargement_ocsge.RData") @@ -127,10 +130,17 @@ etalement_urbain <- etalement_urbain %>% TypeZone = iconv(TypeZone,to = "UTF-8")) %>% mutate(across(where(is.character),as.factor)) +observatoire_artificialisation_gk3 <- observatoire_artificialisation_gk3 %>% + filter(CodeZone %in% liste_52 | TypeZone == "Régions"| TypeZone == "D\u00e9partements") %>% + mutate(Zone = iconv(Zone,to = "UTF-8"), + TypeZone = iconv(TypeZone,to = "UTF-8")) %>% + mutate(across(where(is.character),as.factor)) + rm(liste_52) usethis::use_data(result, overwrite = TRUE, internal = FALSE) usethis::use_data(teruti, overwrite = TRUE, internal = FALSE) usethis::use_data(observatoire_artificialisation, overwrite = TRUE, internal = FALSE) +usethis::use_data(observatoire_artificialisation_gk3, overwrite = TRUE, internal = FALSE) usethis::use_data(etalement_urbain, overwrite = TRUE, internal = FALSE) usethis::use_data(metadata_donnee, overwrite = TRUE, internal = FALSE) diff --git a/data/observatoire_artificialisation_gk3.rda b/data/observatoire_artificialisation_gk3.rda new file mode 100644 index 0000000000000000000000000000000000000000..e9965a47d9915ece81d48a94df6bb12939fce2da Binary files /dev/null and b/data/observatoire_artificialisation_gk3.rda differ diff --git a/devstuff_history.R b/devstuff_history.R index bb1d14d48d58c59db57d6e0dfc2dc2d76d28e7fc..07bb31e8fa602b53b968dbe0b781a5a5b3c64cd9 100644 --- a/devstuff_history.R +++ b/devstuff_history.R @@ -60,6 +60,11 @@ usethis::use_vignette("bb-ch2-2","bb- Chapitre 2 Carte 2") usethis::use_r("creer_carte_2_2") usethis::use_test("creer_carte_2_2") +##creer_graphe_2_3 +usethis::use_vignette("bc-ch2-3","bc- Chapitre 2 Graphe 3") +usethis::use_r("creer_graphe_2_3") +usethis::use_test("creer_graphe_2_3") + ##creer_graphe_2_4 usethis::use_vignette("bd-ch2-4","bd- Chapitre 2 Graphe 4") usethis::use_r("creer_graphe_2_4") diff --git a/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd index 6d18f1b88a97832f5b33d7542e1532ad9f536d07..59b3f8cc95fe436b582ce7df8f73e3ecc2798d7d 100644 --- a/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd @@ -10,6 +10,7 @@ params: millesime_ocsge: 2017 millesime_obs_artif: 2019 millesime_etalement_urbain: 2018 + millesime_obs_artif_gk3: 2019 title: "L'artificialisation des sols en Pays de la loire en `r params$millesime_observatoire_artificialisation`" --- @@ -73,6 +74,9 @@ creer_carte_2_2( params$millesime_obs_artif) +```{r graph du taux d evolution de l artificialisation cadastree des differentes regions,fig.width=9,fig.height=7} +creer_graphe_2_3( params$millesime_obs_artif_gk3) +``` ```{r graph conso espace departements 10 ans,fig.width=5,fig.height=7} creer_graphe_2_4( params$millesime_obs_artif) diff --git a/man/creer_graphe_2_3.Rd b/man/creer_graphe_2_3.Rd new file mode 100644 index 0000000000000000000000000000000000000000..b7788d326c91ee71703257450b29dad188359941 --- /dev/null +++ b/man/creer_graphe_2_3.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/creer_graphe_2_3.R +\name{creer_graphe_2_3} +\alias{creer_graphe_2_3} +\title{Creation du graphique du taux d'evolution 2009/19 (\%) de l'artificialisation cadastree des differentes regions.} +\usage{ +creer_graphe_2_3(millesime_obs_artif_gk3) +} +\arguments{ +\item{millesime_obs_artif_gk3}{une année parmi les millesimes sélectionnables par l'utilisateur, au format numerique.} +} +\value{ +Un diagramme en barres +} +\description{ +Graphique du taux d'evolution 2009/19 (\%) de l'artificialisation cadastree des differentes regions. +} +\examples{ +creer_graphe_2_3(millesime_obs_artif_gk3=2019) +} diff --git a/man/observatoire_artificialisation_gk3.Rd b/man/observatoire_artificialisation_gk3.Rd new file mode 100644 index 0000000000000000000000000000000000000000..3f320cdacf9f4a93aaa1a737d0914f08e1a8254b --- /dev/null +++ b/man/observatoire_artificialisation_gk3.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\encoding{UTF-8} +\name{observatoire_artificialisation_gk3} +\alias{observatoire_artificialisation_gk3} +\title{Table contenant les différents indicateurs de la source observatoire_artificialisation_gk3 utiles pour la publication.} +\format{ +Table de 363090 lignes et 6 colonnes: +\describe{ +\item{TypeZone}{Type de territoire} +\item{CodeZone}{Code du territoire} +\item{Zone}{Libellé du territoire} +\item{date}{Millésime de la source} +\item{surface_artificialisee}{surface artificialisee} +\item{surface_naf}{surface naturelle agricole et forestiere} +} +} +\source{ +\url{https://agreste.agriculture.gouv.fr/agreste-web/disaron/W0020/detail/} +} +\usage{ +observatoire_artificialisation_gk3 +} +\description{ +Table contenant les différents indicateurs de la source observatoire_artificialisation_gk3 utiles pour la publication. +} +\keyword{datasets} diff --git a/tests/testthat/test-creer_graphe_2_3.R b/tests/testthat/test-creer_graphe_2_3.R new file mode 100644 index 0000000000000000000000000000000000000000..c55faafd7a40ba73e70899a83c21dc499cdccbd1 --- /dev/null +++ b/tests/testthat/test-creer_graphe_2_3.R @@ -0,0 +1,7 @@ +test_that("creer_graphe_2_3 fonctionne", { + + # Test que le graphe est un ggplot + objet <- creer_graphe_2_3(millesime_obs_artif_gk3=2019) + testthat::expect_equal(attr(objet, "class"), c("gg","ggplot")) + +}) diff --git a/vignettes/bc-ch2-3.Rmd b/vignettes/bc-ch2-3.Rmd new file mode 100644 index 0000000000000000000000000000000000000000..96acb92d5ae84f32299cec3d823d2a2b22794887 --- /dev/null +++ b/vignettes/bc-ch2-3.Rmd @@ -0,0 +1,30 @@ +--- +title: "bc- Chapitre 2 Graphe 3" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{bc- Chapitre 2 Graphe 3} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + echo = FALSE, + message = FALSE, + warning = FALSE, + error = FALSE, + comment = "#>", + fig.width = 9, + fig.height = 7 +) + +``` + +# Descriptif +La fonction `creer_graphe_2_3()` produit le graphique du taux d'evolution 2009/19 (%) de l'artificialisation cadastree des differentes regions. + +```{r setup} +library(propre.artificialisation) +creer_graphe_2_3(millesime_obs_artif_gk3 = 2019) +``` diff --git a/vignettes/test.R b/vignettes/test.R index 76da18651babc40bc27fc9fa663283d3f57f7e64..bee4bcf6f35b410501573498d11e4b9331472940 100644 --- a/vignettes/test.R +++ b/vignettes/test.R @@ -1,223 +1,58 @@ -#' Creation de la carte de l evolution de l artificialisation sur 10 ans en ha par departement -#' @description Carte de l evolution de l artificialisation sur 10 ans en ha par departement +#' Creation du graphique du taux d'evolution 2009/19 (%) de l'artificialisation cadastree des differentes regions. +#' @description Graphique du taux d'evolution 2009/19 (%) de l'artificialisation cadastree des differentes regions. #' -#' @param millesime_obs_artif une année parmi les millesimes sélectionnables par l'utilisateur, au format numerique. +#' @param millesime_teruti une année parmi les millesimes sélectionnables par l'utilisateur, au format numerique. #' -#' @return Une carte +#' @return Un diagramme en barres #' -#' @importFrom dplyr filter select mutate arrange -#' @importFrom forcats fct_drop fct_relevel -#' @importFrom ggplot2 ggplot geom_bar aes geom_text labs facet_wrap theme element_text scale_y_continuous -#' @importFrom gouvdown scale_fill_gouv_discrete +#' @importFrom dplyr mutate filter select group_by case_when +#' @importFrom forcats fct_reorder +#' @importFrom ggplot2 ggplot aes geom_bar geom_text position_dodge coord_flip labs theme element_text scale_y_continuous #' @importFrom glue glue -#' @importFrom lubridate year -#' @importFrom stringr str_wrap -#' @importFrom mapfactory format_fr +#' @importFrom scales number_format #' #' @export #' #' @examples -#' creer_carte_2_2(millesime_obs_artif = 2019) +#' creer_graphe_2_3(millesime_obs_artif_gk3=2019) -millesime_etalement_urbain=2018 - - data <- etalement_urbain %>% - dplyr::filter(.data$TypeZone == "Communes", - .data$date == lubridate::make_date(millesime_etalement_urbain,"01","01"))%>% - dplyr::mutate(indicateur_etalement_urbain = forcats::fct_rev(.data$indicateur_etalement_urbain)) - - fond_carte <- mapfactory::fond_carto(nom_reg = "Pays de la Loire") - - localisation_classe6 <- fond_carte$communes %>% - dplyr::filter(DEPCOM=="53125") %>% - sf::st_centroid() %>% - sf::st_geometry() %>% - sf::st_coordinates() - - localisation_classe2a <- fond_carte$communes %>% - dplyr::filter(DEPCOM=="44072") %>% - sf::st_point_on_surface() %>% - sf::st_geometry() %>% - sf::st_coordinates() - - # # reflexions sur automatisation du choix communes de référence - # ideal_class3_x <- 390000 #coordonnées du point ideal - # ideal_class3_y <- 6630000 - # choix_class3 <- data %>% - # dplyr::filter(indicateur_etalement_urbain == "classe 3") #on ne conserve que les class 3 - # # ajouter dans cette table une colonne avec les coordonnéesdu centre de la commune - # #et une autre avec celles du point ideal - # # creer une colonne avec une fonction qui calcule la distance entre les 2 colonnes précedentes - # # prendre la valeur la plus faible de cette colonne et extraire le code commune - # # utiliser ce code dans localisation_class_3 - - localisation_classe3 <- fond_carte$communes %>% - dplyr::filter(DEPCOM=="85289") %>% - sf::st_point_on_surface() %>% - sf::st_geometry() %>% - sf::st_coordinates() - -millesime_obs_artif=2019 -library(COGiter) - -creer_graphe_2_2 <- function(millesime_obs_artif) { - - # calcul des millesimes extremes du graphique - millesime_debut <- millesime_obs_artif - 10 - millesime_fin <- millesime_obs_artif - 1 +creer_graphe_2_3 <- function(millesime_obs_artif_gk3){ # Creation de la table utile a la production du graphique - data <- observatoire_artificialisation %>% - dplyr::filter(.data$TypeZone == "D\u00e9partements") %>% - dplyr::filter( !(.data$CodeZone %in% c("971","972","973","974","975","976") )) %>% - dplyr::select(.data$CodeZone,.data$TypeZone, .data$Zone, .data$date, .data$flux_naf_artificialisation_total) %>% - dplyr::mutate(flux_naf_artificialisation_total = .data$flux_naf_artificialisation_total / 10000) %>% - dplyr::mutate(date = as.character(lubridate::year(.data$date - 1))) %>% - dplyr::filter(.data$date < millesime_obs_artif, .data$date > millesime_obs_artif - 11) %>% # conserve les 10 derniers millesimes - dplyr::arrange(.data$Zone) %>% - dplyr::group_by(.data$CodeZone,.data$TypeZone, .data$Zone) %>% - dplyr::summarise(`total en hectares`= sum(.data$flux_naf_artificialisation_total,na.rm=T)) %>% - dplyr::left_join(COGiter::departements_geo,by=c("CodeZone"="DEP")) - data <- sf::st_as_sf(data) - - # creation de la carte - monde_file <- system.file("maps","countries_voisins-10m.gpkg",package = "mapfactory") - monde <- sf::read_sf(monde_file) %>% - dplyr::select(.data$name) - - bbox_reg <- sf::st_bbox(sf::st_buffer(data,50000)) - - y_min = bbox_reg$ymin - y_max = bbox_reg$ymax - x_min = bbox_reg$xmin - x_max = bbox_reg$xmax - - carte_2_2 <- ggplot2::ggplot(data)+ - ggplot2::geom_sf(data = monde,fill="light grey")+ - ggplot2::geom_sf(fill="white")+ - ggplot2::stat_sf_coordinates(ggplot2::aes(size=.data$`total en hectares`, - fill=.data$`total en hectares`), - color="black", - shape=21, - alpha = 0.8)+ - ggplot2::coord_sf( - xlim = c(x_min, x_max), - ylim = c(y_min, y_max), - expand = FALSE, - crs = sf::st_crs(data), - datum = NA - )+ - ggplot2::theme( - panel.background = ggplot2::element_rect(fill = "light blue"))+ - gouvdown::scale_fill_gouv_continuous(palette = "pal_gouv_o", reverse = TRUE, name="")+ - # ggplot2::scale_size_area(name="")+ - # ggplot2::scale_size(range = c(0,15)) - ggplot2::scale_size_continuous(range = c(0,20))+ - ggplot2::labs(title=glue::glue("Surfaces artificialis\u00e9es de {millesime_debut} \u00e0 {millesime_fin}"), - subtitle="", - y="", - x="", - caption = glue::glue("Source : DGFip/Cerema {millesime_obs_artif}")) - - - - - - - - - - return(carte_2_2) -} - - localisation_classe5 <- fond_carte$communes %>% - dplyr::filter(DEPCOM=="49224") %>% - sf::st_point_on_surface() %>% - sf::st_geometry() %>% - sf::st_coordinates() - - carte_3_2 <- mapfactory::creer_carte_categorie_communes(data = data, - code_region=52, - carto = fond_carte, - palette = "pal_gouv_o", - inverse = FALSE, - indicateur = .data$indicateur_etalement_urbain, - titre = glue::glue("Etalement urbain en Pays de la Loire par commune \n au 1er janvier {millesime_etalement_urbain}"), - bas_de_page = glue::glue("Source : {millesime_etalement_urbain}"), - suffixe = NULL - ) + - ggplot2::annotate("curve", - x = 350000, - y=6818000, - xend = localisation_classe6[1], - yend = localisation_classe6[2], - color = "#D66C58", - arrow = ggplot2::arrow(length = ggplot2::unit(0.05, "inches")) - ) + - ggplot2::annotate("label", - x = 350000, - y=6818000, - label="classe 6 :\nTerritoires pour lesquels \nla population décroit et \nl'artificialisation progresse", - label.r = ggplot2::unit(0,"lines"), - size = 3, - family = "Marianne", - fill = "#D66C58", - color = "white") + - ggplot2::annotate("curve", - x = 320000, - y=6760000, - xend = localisation_classe2a[1], - yend = localisation_classe2a[2], - color = "black", - arrow = ggplot2::arrow(length = ggplot2::unit(0.05, "inches")) - ) + - ggplot2::annotate("label", - x = 320000, - y=6760000, - label="classe 2a :\nTerritoires pour lesquels \nla population croit moins vite \nque l'artificialisation", - label.r = ggplot2::unit(0,"lines"), - size = 3, - family = "Marianne", - fill = "#FFF2F1", - color = "black") + - - ggplot2::annotate("curve", - x = 470000, - y=6603000, - xend = localisation_classe3[1], - yend = localisation_classe3[2], - color = "black", - arrow = ggplot2::arrow(length = ggplot2::unit(0.05, "inches")) - ) + - ggplot2::annotate("label", - x = 470000, - y=6603000, - label="classe 3 :\nTerritoires pour lesquels \nla population croit moins vite \nque l'artificialisation", - label.r = ggplot2::unit(0,"lines"), - size = 3, - family = "Marianne", - fill = "#FFC9C2", - color = "black") + - ggplot2::annotate("curve", - x = 500000, - y=6643000, - xend = localisation_classe5[1], - yend = localisation_classe5[2], - color = "black", - arrow = ggplot2::arrow(length = ggplot2::unit(0.05, "inches")) - ) + - ggplot2::annotate("label", - x = 500000, - y=6643000, - label="classe 5 :\nTerritoires pour lesquels \nla population croit moins vite \nque l'artificialisation", - label.r = ggplot2::unit(0,"lines"), - size = 3, - family = "Marianne", - fill = "#F66E4E", - color = "black") - - - - return(carte_3_2) + data <- observatoire_artificialisation_gk3 %>% + dplyr::mutate(date=year(.data$date)) %>% + dplyr::filter(.data$TypeZone == "R\u00e9gions", + !(.data$CodeZone %in% c("01","02","03","04","06")), + .data$date == millesime_obs_artif_gk3 | .data$date == millesime_obs_artif_gk3 - 9) %>% + dplyr::select (-.data$surface_naf) %>% + dplyr::group_by(.data$TypeZone,.data$Zone,.data$CodeZone) %>% + summarise(evolution=round((sum(surface_artificialisee[which(date==2019)],na.rm=T) - sum(surface_artificialisee[which(date==2010)],na.rm=T))/10000,0)) %>% + dplyr::mutate(couleur_barre = dplyr::case_when( + .data$CodeZone=="52"~ 1, + TRUE ~ 0)) + + valeur_max <- max(data$evolution,na.rm=T) + millesime_debut <- millesime_obs_artif_gk3 - 9 + + graph_2_3<-data %>% + ggplot2::ggplot(ggplot2::aes(x=forcats::fct_reorder(.data$Zone,.data$evolution,.desc=F), ymax=valeur_max+5000, y=.data$evolution,fill=.data$couleur_barre)) + + ggplot2::geom_bar(stat="identity")+ + ggplot2::geom_text(ggplot2::aes(y=.data$evolution , + label=.data$evolution, + color = .data$couleur_barre + ), + position= ggplot2::position_dodge(width=1), + vjust=0.5, + hjust=-0.5, + size=3) + + ggplot2::coord_flip(expand = FALSE) + + ggplot2::labs(title=glue::glue("\u00e9volution {millesime_debut} - {millesime_obs_artif_gk3} en hectares\nde l'artificialisation cadastr\u00e9e par r\u00e9gion"), + subtitle="",x="",y="", + fill="", + caption = glue::glue("Source : Observatoire artificialisation {millesime_obs_artif_gk3}"))+ + ggplot2::theme(axis.text.x = ggplot2::element_text(), legend.position = "none") + + ggplot2::scale_y_continuous(labels = scales::number_format(suffix = "", accuracy = 1)) + + return(graph_1_1) }