diff --git a/.gitignore b/.gitignore index ced15ba9f77a230a5fa158fd0cd129909af26c5f..ebd418282458bf4e7f8e237c11f8ef79e3bf8a59 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ inst/doc doc Meta www +/doc/ +/Meta/ diff --git a/DESCRIPTION b/DESCRIPTION index abcbb44797bf1582033df00eb6a2f8fc80d22fbd..89eb5868411f8ad4a6b84f008538d5b62855b59b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,8 +14,8 @@ Authors@R: family = "Theuliere", role = c("aut", "cre"), email = "mael.theuliere@gmail.com")) -Description: The goal of propre.artificialisation is to produce - a publication on land use in Pays de la Loire. +Description: The goal of propre.artificialisation is to produce a + publication on land use in Pays de la Loire. License: GPL (>= 3) Depends: R (>= 2.10) @@ -26,13 +26,15 @@ Imports: forcats, ggiraph, ggplot2, - ggradar, ggtext, glue, gouvdown (>= 0.0.0.9000), + htmlwidgets, + htmltools, lubridate, magrittr, mapfactory (>= 0.0.0.9000), + reactable, scales, sf, stats, @@ -50,7 +52,6 @@ Remotes: gitlab::dreal-datalab/mapfactory, maeltheuliere/COGiter, pachevalier/tricky, - github::ricardo-bion/ggradar, spyrales/gouvdown Config/testthat/edition: 3 Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 78e433fb1a7274132490ae93e3ebdc3847966817..beeda600f56dbf574be90ad27d90a6c7dab121c8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,12 +9,17 @@ export(creer_carte_3_2) export(creer_graphe_1_1) export(creer_graphe_1_4) export(creer_graphe_1_5) +export(creer_graphe_1_6) export(creer_graphe_2_3) export(creer_graphe_2_4) export(creer_graphe_2_5) export(creer_graphe_3_1) export(creer_graphe_3_4) +export(creer_tableau_1_6) export(format_fr_pct) +import(COGiter) +importFrom(COGiter,ajouter_typologie) +importFrom(COGiter,charger_zonage) importFrom(COGiter,filtrer_cog) importFrom(attempt,stop_if_not) importFrom(dplyr,arrange) @@ -29,6 +34,7 @@ importFrom(dplyr,left_join) importFrom(dplyr,mutate) importFrom(dplyr,pull) importFrom(dplyr,rename) +importFrom(dplyr,row_number) importFrom(dplyr,select) importFrom(dplyr,summarise) importFrom(dplyr,ungroup) @@ -71,6 +77,12 @@ importFrom(ggtext,element_textbox_simple) importFrom(glue,glue) importFrom(gouvdown,scale_fill_gouv_continuous) importFrom(gouvdown,scale_fill_gouv_discrete) +importFrom(htmltools,div) +importFrom(htmltools,h2) +importFrom(htmltools,p) +importFrom(htmlwidgets,appendContent) +importFrom(htmlwidgets,prependContent) +importFrom(lubridate,as_date) importFrom(lubridate,make_date) importFrom(lubridate,year) importFrom(magrittr,"%>%") @@ -80,6 +92,10 @@ importFrom(mapfactory,creer_carte_communes_prop) importFrom(mapfactory,fond_carto) importFrom(mapfactory,format_fr) importFrom(mapfactory,format_fr_pct) +importFrom(mapfactory,format_fr_pct_2) +importFrom(reactable,colDef) +importFrom(reactable,reactable) +importFrom(reactable,reactableTheme) importFrom(scales,label_number) importFrom(scales,number_format) importFrom(sf,read_sf) @@ -91,8 +107,11 @@ importFrom(sf,st_crs) importFrom(sf,st_geometry) importFrom(sf,st_point_on_surface) importFrom(stats,quantile) +importFrom(stringr,str_split_fixed) +importFrom(stringr,str_trim) importFrom(stringr,str_wrap) importFrom(tidyr,gather) importFrom(tidyr,pivot_longer) +importFrom(tidyr,pivot_wider) importFrom(tidyr,spread) importFrom(tricky,set_standard_names) diff --git a/NEWS.md b/NEWS.md index 74af4769e8cc2ac7b68196637dba667eb018ea7b..caac5a9e902332ad3294598a3314a326dcb76acb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # propre.artificialisation 0.0.0.9000 * Création site pkgdown -* Ajout fonctions d'illustration `creer_carte_1_3()`,`creer_carte_1_7()`,`creer_carte_2_2()`,`creer_carte_2_7()`,`creer_carte_3_2()`, `creer_graphe_1_1()`, `creer_graphe_1_4()`, `creer_graphe_1_5()`, `creer_graphe_2_3()`, `creer_graphe_2_4()`, `creer_graphe_2_5()`, `creer_graphe_3_1()`, `creer_graphe_3_4()` et leurs tests +* Ajout fonctions d'illustration `creer_carte_1_3()`,`creer_carte_1_7()`,`creer_carte_2_2()`,`creer_carte_2_7()`,`creer_carte_3_2()`, `creer_graphe_1_1()`, `creer_graphe_1_4()`, `creer_graphe_1_5()`,`creer_graphe_1_6()`, `creer_graphe_2_3()`, `creer_graphe_2_4()`, `creer_graphe_2_5()`, `creer_graphe_3_1()`, `creer_graphe_3_4()`,`creer_tableau_1_6()` et leurs tests * Ajout template de publication * Ajout fichier `NEWS.md` pour tracer les changements dans le package. + diff --git a/R/creer_carte_1_3.R b/R/creer_carte_1_3.R index 843ca4ffc59c52ecb8a3d4b56dbebde5377edaab..f15efa663af2209dcec9bc1732bfef06ab8e94d6 100644 --- a/R/creer_carte_1_3.R +++ b/R/creer_carte_1_3.R @@ -5,21 +5,24 @@ #' #' @return Une carte #' -#' @importFrom dplyr filter mutate +#' @importFrom dplyr filter mutate select #' @importFrom glue glue #' @importFrom mapfactory creer_carte_communes_prop fond_carto #' #' @export #' #' @examples -#' creer_carte_1_3(millesime_ocsge=2017) +#' creer_carte_1_3(millesime_ocsge=2016) creer_carte_1_3 <- function(millesime_ocsge){ - data <- result %>% - dplyr::filter(.data$variable == "espace_artificialise") %>% - dplyr::mutate(valeur=round(.data$valeur / 10000,0)) + data <- ocsge %>% + dplyr::filter(grepl(millesime_ocsge, .data$date)) %>% + dplyr::select(.data$TypeZone,.data$Zone,.data$CodeZone,.data$date,.data$espace_artificialise) %>% + dplyr::mutate(valeur=round(.data$espace_artificialise / 10000,0)) %>% + dplyr::select(-.data$espace_artificialise) + fond_carto <- mapfactory::fond_carto(nom_reg = "Pays de la Loire") diff --git a/R/creer_carte_1_7.R b/R/creer_carte_1_7.R index 4c4335693758acce645161c06f1756c7d7ce521c..85b1d43579a6b3c4ecd0d0ce4c5c68c1dbe7fd2e 100644 --- a/R/creer_carte_1_7.R +++ b/R/creer_carte_1_7.R @@ -10,20 +10,22 @@ #' @importFrom lubridate make_date #' @importFrom stats quantile #' @importFrom mapfactory fond_carto creer_carte_communes +#' @importFrom tidyr gather #' #' @export #' #' @examples -#' creer_carte_1_7(millesime_ocsge=2017) +#' creer_carte_1_7(millesime_ocsge=2016) + + + creer_carte_1_7 <- function(millesime_ocsge){ - data <- result %>% - dplyr::mutate(valeur=as.numeric(.data$valeur)) %>% - dplyr::filter(.data$TypeZone == "Communes", - .data$date == lubridate::make_date(millesime_ocsge,"01","01"), - .data$variable %in% c("a_definir","autre_surface_naturelle","espace_agricole", - "espace_artificialise","surface_en_eau","surface_naturelle_boisee")) %>% + data <- ocsge %>% + dplyr::filter(grepl(millesime_ocsge, .data$date), + .data$TypeZone == "Communes") %>% + tidyr::gather(variable,valeur,.data$a_definir:.data$surface_naturelle_boisee) %>% dplyr::arrange(.data$CodeZone) %>% dplyr::group_by(.data$TypeZone,.data$Zone,.data$CodeZone,.data$date) %>% dplyr::summarise(variable=.data$variable,valeur=.data$valeur / sum(.data$valeur,na.rm=T)) %>% @@ -32,6 +34,22 @@ creer_carte_1_7 <- function(millesime_ocsge){ dplyr::select(.data$TypeZone,.data$CodeZone,.data$Zone,.data$date,.data$valeur) %>% dplyr::mutate(valeur=.data$valeur * 100) + + + # data <- result %>% + # dplyr::mutate(valeur=as.numeric(.data$valeur)) %>% + # dplyr::filter(.data$TypeZone == "Communes", + # .data$date == lubridate::make_date(millesime_ocsge,"01","01"), + # .data$variable %in% c("a_definir","autre_surface_naturelle","espace_agricole", + # "espace_artificialise","surface_en_eau","surface_naturelle_boisee")) %>% + # dplyr::arrange(.data$CodeZone) %>% + # dplyr::group_by(.data$TypeZone,.data$Zone,.data$CodeZone,.data$date) %>% + # dplyr::summarise(variable=.data$variable,valeur=.data$valeur / sum(.data$valeur,na.rm=T)) %>% + # dplyr::filter(.data$variable == "espace_artificialise") %>% + # dplyr::ungroup() %>% + # dplyr::select(.data$TypeZone,.data$CodeZone,.data$Zone,.data$date,.data$valeur) %>% + # dplyr::mutate(valeur=.data$valeur * 100) + fond_carto <- mapfactory::fond_carto(nom_reg = "Pays de la Loire") bins <- stats::quantile(data$valeur,probs = c(0,0.1, 0.25, 0.5,0.75,0.9,1),na.rm=TRUE) diff --git a/R/creer_graphe_1_6.R b/R/creer_graphe_1_6.R new file mode 100644 index 0000000000000000000000000000000000000000..a5c89a1256be1c77f8662774fb77048af508e83f --- /dev/null +++ b/R/creer_graphe_1_6.R @@ -0,0 +1,107 @@ +#' Creation du graphique de l artificialisation OCSGE par type de territoire. +#' @description Graphique de l artificialisation OCSGE par type de territoire. +#' +#' @param millesime_ocsge une annee parmi les millesimes selectionnables par l'utilisateur, au format numerique. +#' @return Un graphique en barres +#' @import COGiter +#' +#' @importFrom COGiter charger_zonage ajouter_typologie +#' @importFrom dplyr mutate filter select group_by summarise ungroup arrange +#' @importFrom ggplot2 ggplot aes geom_point position_dodge geom_linerange geom_label coord_flip scale_y_continuous labs theme element_blank element_text scale_color_manual +#' @importFrom ggtext element_textbox_simple +#' @importFrom glue glue +#' @importFrom lubridate year as_date +#' @importFrom mapfactory format_fr_pct_2 +#' @importFrom scales label_number +#' @importFrom tidyr pivot_longer +#' @importFrom forcats fct_drop fct_inorder fct_rev +#' +#' @export +#' +#' @examples +#' creer_graphe_1_6(millesime_ocsge = 2016) +creer_graphe_1_6 <- function(millesime_ocsge = NULL) { + + # preparation des donnees + ocsge2 <- ocsge %>% + dplyr::mutate( + date = lubridate::year(lubridate::as_date(.data$date)), + espace_naturel = .data$autre_surface_naturelle + .data$surface_en_eau + .data$surface_naturelle_boisee + ) %>% + dplyr::filter(.data$date == millesime_ocsge, .data$TypeZone %in% c("Communes", "R\u00e9gions")) %>% + dplyr::select( + .data$TypeZone, .data$Zone, .data$CodeZone, + .data$espace_naturel, + .data$espace_agricole, .data$espace_artificialise + ) + + zonage_aav <- COGiter::charger_zonage("CATEAAV2020") + + ocsge3 <- COGiter::ajouter_typologie(ocsge2, + zonage_df = zonage_aav, + departements = FALSE, + regions = TRUE, + metro = FALSE, + metrodrom = FALSE, + drom = FALSE, franceprovince = FALSE + ) %>% + dplyr::filter( + !(.data$TypeZone %in% c("Communes")), + stringr::str_detect(.data$CodeZone, "NA", negate = TRUE) + ) %>% + dplyr::arrange(.data$CodeZone) + + # preparation graphiques + data <- ocsge3 %>% + tidyr::pivot_longer(.data$espace_naturel:.data$espace_artificialise, + names_to = "variable", + values_to = "valeur" + ) %>% + dplyr::group_by(.data$TypeZone, .data$Zone, .data$CodeZone) %>% + dplyr::mutate( + variable = .data$variable, + valeur = .data$valeur / 10000, + taux = .data$valeur / sum(.data$valeur, na.rm = T) * 100 + ) %>% + dplyr::ungroup() %>% + mutate(Zone = forcats::fct_drop(.data$Zone) %>% + forcats::fct_inorder() %>% + forcats::fct_rev(), + variable = forcats::fct_relevel(variable,"espace_naturel","espace_agricole","espace_artificialise")) + + + + # graphique pourcentages + graph_1_6 <- data %>% + ggplot2::ggplot() + + ggplot2::aes(x = .data$Zone, y = .data$taux, ymin = 0, ymax = .data$taux, group = .data$variable, color = .data$variable) + + ggplot2::geom_linerange(size = 1.1, position = ggplot2::position_dodge(width = 0.5)) + + ggplot2::geom_point(size = 1.5, position = ggplot2::position_dodge(width = 0.5)) + + ggplot2::aes(label = mapfactory::format_fr_pct_2(.data$taux)) + + ggplot2::geom_label( + position = ggplot2::position_dodge(width = 0.5), + vjust = 0.5, hjust = -0.5, alpha = .7 + ) + + ggplot2::coord_flip() + + ggplot2::scale_y_continuous( + limits = c(0, max(data$taux) * 1.2), + labels = scales::label_number(big.mark = " ", decimal.mark = ",", suffix = " %"), + expand = c(0, 0) + ) + + ggplot2::labs( + title = "R\u00e9partition des surfaces entre <span style = 'color:#FF8D7E'>espaces artificialis\u00e9s </span>, <br> <span style = 'color:#E3CE00'>espaces agricoles</span> et <span style = 'color:#169B62'>espaces naturels </span>", + subtitle = glue::glue("en {millesime_ocsge}, en %"), + caption = glue::glue("Source : OCSGE {millesime_ocsge}"), + x = NULL, y = NULL + ) + + ggplot2::theme( + panel.grid.major.y = ggplot2::element_blank(), + legend.position = "none", + plot.title = ggtext::element_textbox_simple(size = 14, lineheight = 1, hjust = 0), + plot.subtitle = ggplot2::element_text(size = 12), + plot.caption = ggplot2::element_text(size = 10), + ) + + ggplot2::scale_color_manual(values = c("#169B62","#E3CE00","#FF8D7E" )) + + return(graph_1_6) +} diff --git a/R/creer_tableau_1_6.R b/R/creer_tableau_1_6.R new file mode 100644 index 0000000000000000000000000000000000000000..6e69bee8276384f1f2d575f3da710179f88196f0 --- /dev/null +++ b/R/creer_tableau_1_6.R @@ -0,0 +1,152 @@ +#' Creation du tableau de l artificialisation OCSGE par type de territoire par departement. +#' @description Graphique de l artificialisation OCSGE par type de territoire par departement. +#' +#' @param millesime_ocsge une annee parmi les millesimes selectionnables par l'utilisateur, au format numerique. +#' +#' @return Un tableau +#' @import COGiter +#' +#' @importFrom COGiter charger_zonage ajouter_typologie +#' @importFrom dplyr mutate filter select group_by summarise ungroup row_number +#' @importFrom lubridate year as_date +#' @importFrom reactable reactable reactableTheme colDef +#' @importFrom stringr str_split_fixed str_trim +#' @importFrom tidyr pivot_longer pivot_wider +#' @importFrom htmltools div p h2 +#' @importFrom htmlwidgets prependContent appendContent +#' +#' @export +#' +#' @examples +#' creer_tableau_1_6(millesime_ocsge = 2016) + +creer_tableau_1_6 <- function(millesime_ocsge = NULL){ + +# preparation des donnees +ocsge2 <- ocsge %>% + dplyr::mutate(date=lubridate::year(lubridate::as_date(.data$date)), + espace_naturel= .data$autre_surface_naturelle + .data$surface_en_eau + .data$surface_naturelle_boisee) %>% + dplyr::filter(.data$date == millesime_ocsge) %>% + dplyr::select (.data$TypeZone,.data$Zone,.data$CodeZone, + .data$espace_naturel, + .data$espace_agricole,.data$espace_artificialise) %>% + dplyr::filter(.data$TypeZone == "Communes") + +zonage_aav <- COGiter::charger_zonage("CATEAAV2020") + +ocsge3 <- COGiter::ajouter_typologie(ocsge2, + zonage_df = zonage_aav, + departements = TRUE, + regions = FALSE, + metro = FALSE, + metrodrom = FALSE, + drom = FALSE, franceprovince = FALSE +) %>% + dplyr::filter( + !(.data$TypeZone %in% c("Communes")), + stringr::str_detect(.data$CodeZone, "NA", negate = TRUE) + ) + +# preparation graphiques +data <- ocsge3 %>% + tidyr::gather(variable,valeur,.data$espace_naturel:.data$espace_artificialise)%>% + dplyr::group_by(.data$TypeZone,.data$Zone,.data$CodeZone) %>% + dplyr::mutate(variable=.data$variable,valeur=.data$valeur/10000, taux=.data$valeur / sum(.data$valeur,na.rm=T)*100) %>% + dplyr::ungroup() + +# donnees du tableau +data2 <- data %>% + dplyr::filter(.data$TypeZone == "CATEAAV2020 - D\u00e9partements") %>% + dplyr::select (.data$CodeZone,.data$Zone,.data$variable,.data$taux)%>% + tidyr::pivot_wider(names_from = "variable",values_from="taux",values_fill=0)%>% + dplyr::mutate(TypeZone=stringr::str_split_fixed(.data$Zone," - ",n=2)[,1], + Departement=stringr::str_split_fixed(.data$Zone," - ",n=2)[,2]) %>% + dplyr::select (.data$TypeZone,.data$Departement,.data$espace_agricole,.data$espace_artificialise,.data$espace_naturel) + + data <- data2 %>% + dplyr::group_by(.data$TypeZone) %>% + dplyr::mutate(n = dplyr::row_number(), + nmax=(.data$n==max(.data$n))) %>% + dplyr::ungroup() %>% + dplyr::mutate(TypeZone = ifelse(.data$n == 1, .data$TypeZone, "")) %>% + dplyr::select(.data$TypeZone, .data$Departement, .data$espace_artificialise, .data$espace_agricole, .data$espace_naturel,.data$nmax) + # Render a bar chart with a label on the left + bar_chart <- function(label, width = "100%", height = "14px", fill = "#00bfc4", background = NULL) { + bar <- htmltools::div(style = list(background = fill, width = width, height = height)) + chart <- htmltools::div(style = list(flexGrow = 1, marginLeft = "6px", background = background), bar) + htmltools::div(style = list(display = "flex", alignItems = "center"), label, chart) + } + tableau_1_6 <- reactable::reactable( + data %>% dplyr::select(-.data$nmax), + defaultPageSize = 100, + sortable = FALSE, + rowStyle = function(index) { + if (data[index, "nmax"] == TRUE) { + list(borderBottom = "1pt solid #DEDEDE") + } + }, + defaultColDef = reactable::colDef(headerStyle = "border-bottom: 2px solid #555;"), + theme = reactable::reactableTheme( + style = list(fontFamily = "Marianne"), + ), + columns = list( + TypeZone = reactable::colDef( + name = "Type de territoire" + ), + Departement = reactable::colDef( + name = "D\u00e9partement" + ), + espace_agricole = reactable::colDef( + name = "Espaces agricoles", + cell = function(value) { + # Format as percentages with 1 decimal place + width <- paste0(format(value, nsmall = 1), "%") + label <- paste0(format(value, nsmall = 1, decimal.mark = ",",digits = 1), "%") + label <- ifelse(value<10, paste0("0", stringr::str_trim(label)), label)#pour gerer les valeurs à l'unite + bar_chart(label, width = width, fill = "#E3CE00", background = "#e1e1e1") + }, + # And left-align the columns + align = "left" + ), + espace_artificialise = reactable::colDef( + name = "Espaces artificialis\u00e9s", + cell = function(value) { + # Format as percentages with 1 decimal place + width <- paste0(format(value, nsmall = 1), "%") + label <- paste0(format(value, nsmall = 1, decimal.mark = ",",digits = 1), "%") + label <- ifelse(value<10, paste0("0", stringr::str_trim(label)), label)#pour gerer les valeurs à l'unite + bar_chart(label, width = width, fill = "#FF8D7E", background = "#e1e1e1") + }, + # And left-align the columns + align = "left" + ), + espace_naturel = reactable::colDef( + name = "Espaces naturels", + cell = function(value) { + # Format as percentages with 1 decimal place + width <- paste0(format(value, nsmall = 1), "%") + label <- paste0(format(value, nsmall = 1, decimal.mark = ",",digits = 1), "%") + label <- ifelse(value<10, paste0("0", stringr::str_trim(label)), label)#pour gerer les valeurs à l'unite + bar_chart(label, width = width, fill = "#169B62", background = "#e1e1e1") + }, + # And left-align the columns + align = "left" + ) + ) + ) + css_header <- "font-family: Marianne;" + css_caption <- "font-family: Marianne;text-align: right;" + tableau_1_6_with_title <- htmlwidgets::prependContent(tableau_1_6, + htmltools::h2(style = css_header, "R\u00e9partition de l'occupation du sol"), + htmltools::p(style = css_header,"Par d\u00e9partement et aire d'attraction des villes") + ) + tableau_1_6_with_caption <- htmlwidgets::appendContent(tableau_1_6_with_title, + htmltools::p(style = css_caption,glue::glue("Source : OCSGE {millesime_ocsge}") + ) + ) +return(tableau_1_6_with_caption) + + +} + + diff --git a/R/data.R b/R/data.R index 226b1233f8eb280776e0e26b01ca9d3c3920031f..82e4c74655d7258c50592c603608d1ad5a87ef58 100644 --- a/R/data.R +++ b/R/data.R @@ -102,3 +102,22 @@ #' } #' @source \url{https://agreste.agriculture.gouv.fr/agreste-web/disaron/W0020/detail/} "population_legale" + +#' Table contenant les différents indicateurs de la source OCSGE pour la publication. +#' +#' @encoding UTF-8 +#' @format Table de 2630 lignes et 10 colonnes: +#' \describe{ +#' \item{TypeZone}{Type de territoire} +#' \item{Zone}{Libellé du territoire} +#' \item{CodeZone}{Code du territoire} +#' \item{date}{Millésime de la source} +#' \item{a_definir}{a definir} +#' \item{autre_surface_naturelle}{autre surface naturelle} +#' \item{espace_agricole}{espace agricole} +#' \item{espace_artificialise}{espace artificialise} +#' \item{surface_en_eau}{surface en eau} +#' \item{surface_naturelle_boisee}{surface naturelle boisee} +#' } +#' @source \url{https://agreste.agriculture.gouv.fr/agreste-web/disaron/W0020/detail/} +"ocsge" diff --git a/R/globals.R b/R/globals.R index cb9335c66f5873059aaab4648a3df09347de1283..e1833d1b308e8380bbe1d430074ec9c4b7bdd330 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","observatoire_artificialisation_gk3","population_legale") + "valeur","etalement_urbain","observatoire_artificialisation_gk3","population_legale","ocsge") ) diff --git a/data-raw/dataprep.R b/data-raw/dataprep.R index 92aedf1e3501ee8de6442af16a3c2423ec2c72f9..b253992f86bdff8038e7d055f69eebd41707dd9d 100644 --- a/data-raw/dataprep.R +++ b/data-raw/dataprep.R @@ -73,14 +73,14 @@ population_legale<-dbReadTable(con_datamart, c("portrait_territoires","cogifiee_population_legale")) -# chargement donnees population legale depuis SGBD -population_legale<-dbReadTable(con_datamart, - c("portrait_territoires","cogifiee_population_legale")) +# chargement donnees ocsge depuis SGBD +ocsge<-dbReadTable(con_datamart, + c("portrait_territoires","cogifiee_ocsge")) # chargement des tables cogifiées d'indicateurs territoriaux load("extdata/cogifiee_chargement_ocsge.RData") -ocsge <- data_cogifiee %>% +ocsge_it <- data_cogifiee %>% mutate(variable = str_replace(variable, "a_définir", "a_definir")) load("extdata/cogifiee_chargement_pci.RData") pci <- data_cogifiee @@ -94,7 +94,7 @@ load("extdata/indicateur_pci_lgt_rgp_insee.RData") load("extdata/indicateur_pci_population_legale.RData") result <- bind_rows( - ocsge, pci, + ocsge_it, pci, pop_rgp_insee, indicateur_observatoire_artificialisation_geokit3, indicateur_observatoire_artificialisation_population_legale_cogiter, @@ -102,7 +102,7 @@ result <- bind_rows( indicateur_pci_population_legale ) rm( - data_cogifiee, ocsge, pci, + data_cogifiee, ocsge_it, pci, pop_rgp_insee, indicateur_observatoire_artificialisation_population_legale_cogiter, indicateur_observatoire_artificialisation_geokit3, @@ -149,7 +149,11 @@ population_legale<- population_legale %>% TypeZone = iconv(TypeZone,to = "UTF-8")) %>% mutate(across(where(is.character),as.factor)) - +ocsge<- ocsge %>% + 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)) @@ -162,5 +166,6 @@ usethis::use_data(observatoire_artificialisation, overwrite = TRUE, internal = F usethis::use_data(observatoire_artificialisation_gk3, overwrite = TRUE, internal = FALSE) usethis::use_data(etalement_urbain, overwrite = TRUE, internal = FALSE) usethis::use_data(population_legale, overwrite = TRUE, internal = FALSE) +usethis::use_data(ocsge, overwrite = TRUE, internal = FALSE) usethis::use_data(metadata_donnee, overwrite = TRUE, internal = FALSE) diff --git a/data/etalement_urbain.rda b/data/etalement_urbain.rda index efd499a48116078048d4bd171d783df66d828347..17fb77d8efa7f4c52c470281cacb43520d203599 100644 Binary files a/data/etalement_urbain.rda and b/data/etalement_urbain.rda differ diff --git a/data/metadata_donnee.rda b/data/metadata_donnee.rda index 78c958493d6dc9974ffff784b3998af027275dc7..fa4805d4ce3244a950fa7e3247d965fcaa37afbd 100644 Binary files a/data/metadata_donnee.rda and b/data/metadata_donnee.rda differ diff --git a/data/observatoire_artificialisation.rda b/data/observatoire_artificialisation.rda index 31b362548fbe41af3fe63dfb653c00b6af7e5eb7..3a0bc2951a246c238c304306267499f7914d46f7 100644 Binary files a/data/observatoire_artificialisation.rda and b/data/observatoire_artificialisation.rda differ diff --git a/data/observatoire_artificialisation_gk3.rda b/data/observatoire_artificialisation_gk3.rda index e9965a47d9915ece81d48a94df6bb12939fce2da..6f307da9250591685aea613ac0ddd9fc4b9860df 100644 Binary files a/data/observatoire_artificialisation_gk3.rda and b/data/observatoire_artificialisation_gk3.rda differ diff --git a/data/ocsge.rda b/data/ocsge.rda new file mode 100644 index 0000000000000000000000000000000000000000..acc277b35a7c72e636b9f01204fb21fedb7a4eb3 Binary files /dev/null and b/data/ocsge.rda differ diff --git a/data/population_legale.rda b/data/population_legale.rda index 2fff93e5b317b65f1d700b9cb4d8fe260696d227..a73e8e1bbe4db4e6c8f0e1ffab37e5ed7399e664 100644 Binary files a/data/population_legale.rda and b/data/population_legale.rda differ diff --git a/data/result.rda b/data/result.rda index ee6507087219ae9adb475f7249a4038cbce5c0dc..ca420a5c8da8a759290a30486953f1a2bcc5cc31 100644 Binary files a/data/result.rda and b/data/result.rda differ diff --git a/data/teruti.rda b/data/teruti.rda index 60723695fc1c71f788fff0b18bafd7158358963f..80f00ed6907d7c2e6a6eaa355fd047026c183011 100644 Binary files a/data/teruti.rda and b/data/teruti.rda differ diff --git a/devstuff_history.R b/devstuff_history.R index d9afcb362843dc1cdf4ed624488ffa012da2fb8d..62f89746e7623e2ccba40f85c52680b442e7f0a9 100644 --- a/devstuff_history.R +++ b/devstuff_history.R @@ -19,6 +19,9 @@ usethis::use_package("lubridate") usethis::use_package("mapfactory") usethis::use_package("sf") usethis::use_package("ggradar") +usethis::use_package("htmlwidgets") + + usethis::use_dev_package("COGiter",remote = "maeltheuliere/COGiter") usethis::use_dev_package("gouvdown",remote = "spyrales/gouvdown") usethis::use_dev_package("mapfactory",remote = "gitlab::dreal-datalab/mapfactory") @@ -51,6 +54,15 @@ usethis::use_vignette("ae-ch1-5","ae- Chapitre 1 Graphe 5") usethis::use_r("creer_graphe_1_5") usethis::use_test("creer_graphe_1_5") +##creer_graphe_1_6 +usethis::use_vignette("af-ch1-6","af- Chapitre 1 Graphe 6") +usethis::use_r("creer_graphe_1_6") +usethis::use_test("creer_graphe_1_6") + +##creer_tableau_1_6 +usethis::use_r("creer_tableau_1_6") +usethis::use_test("creer_tableau_1_6") + ##creer_carte_1_7 usethis::use_vignette("af-ch1-7","af- Chapitre 1 Carte 7") usethis::use_r("creer_carte_1_7") diff --git a/inst/extdata/mes_barres.css b/inst/extdata/mes_barres.css new file mode 100644 index 0000000000000000000000000000000000000000..ab581b1264f094aaaa5d1dd5f587148b95915b6a --- /dev/null +++ b/inst/extdata/mes_barres.css @@ -0,0 +1,13 @@ +.bar-cell { + display: flex; + align-items: center; +}.number { + font-size: 13.5px; + white-space: pre; +}.bar-chart { + flex-grow: 1; + margin-left: 6px; + height: 22px; +}.bar { + height: 100%; +} \ No newline at end of file diff --git a/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd index cba366ef6d8faeeeb237c84c577c161be04718d7..652fc7c49f15657db38671b8414d4102eda934c3 100644 --- a/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/publication/skeleton/skeleton.Rmd @@ -7,7 +7,7 @@ output: logo: "prefecture_r52" params: millesime_teruti: 2018 - millesime_ocsge: 2017 + millesime_ocsge: 2016 millesime_obs_artif: 2019 millesime_etalement_urbain: 2018 millesime_obs_artif_gk3: 2019 @@ -22,6 +22,7 @@ library(gouvdown) library(propre.artificialisation) ggplot2::theme_set(gouvdown::theme_gouv(plot_title_size = 14, subtitle_size = 12, base_size = 10, caption_size = 10) + ggplot2::theme(plot.caption.position = "plot")) +ggplot2::update_geom_defaults("label",list(family = "Marianne")) ``` texte d'introduction... @@ -61,6 +62,17 @@ texte... ```{r graph surfaces artificialisees en volume} creer_graphe_1_4( params$millesime_teruti) ``` +texte... + + +```{r graph artificialisation OCSGE} +creer_graphe_1_6( params$millesime_ocsge) +``` +texte... + +```{r tableau artificialisation OCSGE} +creer_tableau_1_6( params$millesime_ocsge) +``` ```{r carte part du territoire communal artificialise, fig.width=9,fig.height=7} creer_carte_1_7( params$millesime_ocsge) diff --git a/man/creer_carte_1_3.Rd b/man/creer_carte_1_3.Rd index a678fcbe7b4ff3449df89f551df580ced5b0ed43..bbefdb563791a8c96d5153efe5615d6d95d00386 100644 --- a/man/creer_carte_1_3.Rd +++ b/man/creer_carte_1_3.Rd @@ -16,5 +16,5 @@ Une carte Carte communale Pays de la Loire de l'artificialisation en volume selon OCSGE } \examples{ -creer_carte_1_3(millesime_ocsge=2017) +creer_carte_1_3(millesime_ocsge=2016) } diff --git a/man/creer_carte_1_7.Rd b/man/creer_carte_1_7.Rd index da4ca4bfafc5563a9c1ba42efd89ff60f5f520e4..cafb4b3c1fe409c43b6f1878221f070a2041afaa 100644 --- a/man/creer_carte_1_7.Rd +++ b/man/creer_carte_1_7.Rd @@ -16,5 +16,5 @@ Une carte Carte de la part du territoire communal artificialise selon OCSGE } \examples{ -creer_carte_1_7(millesime_ocsge=2017) +creer_carte_1_7(millesime_ocsge=2016) } diff --git a/man/creer_graphe_1_6.Rd b/man/creer_graphe_1_6.Rd new file mode 100644 index 0000000000000000000000000000000000000000..cd66a30ca8f455891b256288d7cdd7ede372835b --- /dev/null +++ b/man/creer_graphe_1_6.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/creer_graphe_1_6.R +\name{creer_graphe_1_6} +\alias{creer_graphe_1_6} +\title{Creation du graphique de l artificialisation OCSGE par type de territoire.} +\usage{ +creer_graphe_1_6(millesime_ocsge = NULL) +} +\arguments{ +\item{millesime_ocsge}{une annee parmi les millesimes selectionnables par l'utilisateur, au format numerique.} +} +\value{ +Un graphique en barres +} +\description{ +Graphique de l artificialisation OCSGE par type de territoire. +} +\examples{ +creer_graphe_1_6(millesime_ocsge = 2016) +} diff --git a/man/creer_tableau_1_6.Rd b/man/creer_tableau_1_6.Rd new file mode 100644 index 0000000000000000000000000000000000000000..9fe3fa3970d7b46620875dca187d5c8b5da31ec2 --- /dev/null +++ b/man/creer_tableau_1_6.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/creer_tableau_1_6.R +\name{creer_tableau_1_6} +\alias{creer_tableau_1_6} +\title{Creation du tableau de l artificialisation OCSGE par type de territoire par departement.} +\usage{ +creer_tableau_1_6(millesime_ocsge = NULL) +} +\arguments{ +\item{millesime_ocsge}{une annee parmi les millesimes selectionnables par l'utilisateur, au format numerique.} +} +\value{ +Un tableau +} +\description{ +Graphique de l artificialisation OCSGE par type de territoire par departement. +} +\examples{ +creer_tableau_1_6(millesime_ocsge = 2016) +} diff --git a/man/ocsge.Rd b/man/ocsge.Rd new file mode 100644 index 0000000000000000000000000000000000000000..abba9ae1b9a622bd01f47b6820c04cda783671ab --- /dev/null +++ b/man/ocsge.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\encoding{UTF-8} +\name{ocsge} +\alias{ocsge} +\title{Table contenant les différents indicateurs de la source OCSGE pour la publication.} +\format{ +Table de 2630 lignes et 10 colonnes: +\describe{ +\item{TypeZone}{Type de territoire} +\item{Zone}{Libellé du territoire} +\item{CodeZone}{Code du territoire} +\item{date}{Millésime de la source} +\item{a_definir}{a definir} +\item{autre_surface_naturelle}{autre surface naturelle} +\item{espace_agricole}{espace agricole} +\item{espace_artificialise}{espace artificialise} +\item{surface_en_eau}{surface en eau} +\item{surface_naturelle_boisee}{surface naturelle boisee} +} +} +\source{ +\url{https://agreste.agriculture.gouv.fr/agreste-web/disaron/W0020/detail/} +} +\usage{ +ocsge +} +\description{ +Table contenant les différents indicateurs de la source OCSGE pour la publication. +} +\keyword{datasets} diff --git a/propre.artificialisation.Rproj b/propre.artificialisation.Rproj index 69fafd4b6dddad27500cfc67efb9fb16e86a96bd..4adc5c8d1d1009ce845fc96061fbb03ab53f5c0c 100644 --- a/propre.artificialisation.Rproj +++ b/propre.artificialisation.Rproj @@ -19,4 +19,7 @@ LineEndingConversion: Posix BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source +PackageBuildArgs: --no-build-vignettes +PackageBuildBinaryArgs: --no-build-vignettes +PackageCheckArgs: --no-build-vignettes PackageRoxygenize: rd,collate,namespace diff --git a/tests/testthat/test-creer_carte_1_3.R b/tests/testthat/test-creer_carte_1_3.R index 5b2f55eff3b5458d50a6fefd80d8f8ae570771e4..27db4051bd3dd0cf39b459e96356fb7f6d54524f 100644 --- a/tests/testthat/test-creer_carte_1_3.R +++ b/tests/testthat/test-creer_carte_1_3.R @@ -1,7 +1,7 @@ test_that("creer_CARTE_1_3 fonctionne", { # Test que la carte est un ggplot - objet <- creer_carte_1_3(millesime_ocsge = 2017) + objet <- creer_carte_1_3(millesime_ocsge = 2016) testthat::expect_equal(attr(objet, "class"), c("gg","ggplot")) }) diff --git a/tests/testthat/test-creer_carte_1_7.R b/tests/testthat/test-creer_carte_1_7.R index ff88beaebdeeca05614e797617d797acba20b456..9897c9b7f0d62c0a1c8e24d5062be7cd4029fba9 100644 --- a/tests/testthat/test-creer_carte_1_7.R +++ b/tests/testthat/test-creer_carte_1_7.R @@ -1,7 +1,7 @@ test_that("creer_carte_1_7 fonctionne", { # Test que la carte est un ggplot - objet <- creer_carte_1_7(millesime_ocsge = 2017) + objet <- creer_carte_1_7(millesime_ocsge = 2016) testthat::expect_equal(attr(objet, "class"), c("gg","ggplot")) }) diff --git a/tests/testthat/test-creer_graphe_1_6.R b/tests/testthat/test-creer_graphe_1_6.R new file mode 100644 index 0000000000000000000000000000000000000000..841d2cf4b38f5de9a0a4d7b1c0145362c222b06f --- /dev/null +++ b/tests/testthat/test-creer_graphe_1_6.R @@ -0,0 +1,7 @@ +test_that("creer_graphe_1_6 fonctionne", { + + # Test que le graphe est un ggplot + objet <- creer_graphe_1_6(millesime_ocsge = 2016) + testthat::expect_equal(attr(objet, "class"), c("gg","ggplot")) + +}) diff --git a/tests/testthat/test-creer_tableau_1_6.R b/tests/testthat/test-creer_tableau_1_6.R new file mode 100644 index 0000000000000000000000000000000000000000..ef55a7fab815cfd60771c2532c682e727bc52fcd --- /dev/null +++ b/tests/testthat/test-creer_tableau_1_6.R @@ -0,0 +1,7 @@ +test_that("creer_tableau_1_6 fonctionne", { + + # Test que le tableau est un reactable + objet <- creer_tableau_1_6(millesime_ocsge = 2016) + testthat::expect_equal(attr(objet, "class"), c("reactable","htmlwidget")) + +}) diff --git a/vignettes/ac-ch1-3.Rmd b/vignettes/ac-ch1-3.Rmd index 89cca9f53c8f9d03328a23ae8edc048298e3bee8..1aa7341588f01d4df9cddf2ff99c82d37c1a3866 100644 --- a/vignettes/ac-ch1-3.Rmd +++ b/vignettes/ac-ch1-3.Rmd @@ -26,5 +26,5 @@ La fonction `creer_carte_1_3()` produit la carte communale des Pays de la Loire ```{r viz} library(propre.artificialisation) -creer_carte_1_3(millesime_ocsge=2017) +creer_carte_1_3(millesime_ocsge=2016) ``` diff --git a/vignettes/af-ch1-6.Rmd b/vignettes/af-ch1-6.Rmd new file mode 100644 index 0000000000000000000000000000000000000000..d2d43817aead5bdef56ab20a8acfa89bd5905740 --- /dev/null +++ b/vignettes/af-ch1-6.Rmd @@ -0,0 +1,41 @@ +--- +title: "af- Chapitre 1 Graphe 6" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{af- Chapitre 1 Graphe 6} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + echo = FALSE, + message = FALSE, + warning = FALSE, + error = FALSE, + comment = "#>" +) + +``` + +# Descriptif +La fonction `creer_graphe_1_6()` produit le graphique de l artificialisation OCSGE par type de territoire. +La fonction `creer_tableau_1_6()` produit le tableau de l artificialisation OCSGE par type de territoire par departement. + + +```{r viz, fig.height=5,fig.width=8} +library(propre.artificialisation) +library(COGiter) +library(gouvdown) +ggplot2::theme_set(gouvdown::theme_gouv(plot_title_size = 14, subtitle_size = 12, base_size = 10, caption_size = 10,strip_text_size = 10)) + +creer_graphe_1_6(millesime_ocsge = 2016) +``` + +```{r tab, fig.height=5,fig.width=8} +library(propre.artificialisation) +library(COGiter) + +creer_tableau_1_6(millesime_ocsge = 2016) +``` diff --git a/vignettes/af-ch1-7.Rmd b/vignettes/af-ch1-7.Rmd index a412e8459a7b1744c3d2a99a3af33d54ebd2e3de..368d99da1e455d653be45d2ab665ed82a551be6e 100644 --- a/vignettes/af-ch1-7.Rmd +++ b/vignettes/af-ch1-7.Rmd @@ -26,5 +26,5 @@ La fonction `creer_carte_1_7()` produit la carte de la part du territoire commun ```{r setup} library(propre.artificialisation) -creer_carte_1_7(millesime_ocsge=2017) +creer_carte_1_7(millesime_ocsge=2016) ``` diff --git a/vignettes/test.R b/vignettes/test.R index 6d4e0101ea8b9072d9ee0f5950f4e3dadf3e45d8..8180bc9586ebced838a5465d59cf56c04f20d7aa 100644 --- a/vignettes/test.R +++ b/vignettes/test.R @@ -1,93 +1,87 @@ -#' Creation du graphique araignee de l etalement urbain par departement sur 10 ans. -#' @description Graphique araignee de l etalement urbain par departement sur 10 ans. +#' Creation du graphique de l artificialisation OCSGE par type de territoire. +#' @description Graphique de l artificialisation OCSGE par type de territoire. #' -#' @param millesime_obs_artif_gk3 une année parmi les millesimes sélectionnables par l'utilisateur, au format numerique. -#' @param millesime_population une année parmi les millesimes sélectionnables par l'utilisateur, au format numerique. +#' @param millesime_ocsge une annee parmi les millesimes selectionnables par l'utilisateur, au format numerique. #' -#' @return Un graphique araignee +#' @return Un graphique en barres #' -#' @importFrom dplyr mutate filter select group_by ungroup -#' @importFrom ggplot2 labs theme -#' @importFrom ggtext element_markdown +#' @importFrom dplyr mutate filter select group_by summarise ungroup +#' @importFrom ggplot2 ggplot aes geom_point position_dodge geom_linerange geom_label coord_flip scale_y_continuous labs theme element_blank element_text scale_color_manual +#' @importFrom ggtext element_textbox_simple #' @importFrom glue glue -#' @importFrom tidyr spread +#' @importFrom lubridate year as_date +#' @importFrom mapfactory format_fr_pct +#' @importFrom scales label_number +#' @importFrom tidyr gather +#' @importFrom dplyr mutate filter select group_by summarise ungroup +#' @importFrom ggplot2 ggplot aes geom_point position_dodge geom_linerange geom_label coord_flip scale_y_continuous labs theme element_blank element_text scale_color_manual +#' @importFrom ggtext element_textbox_simple +#' @importFrom glue glue +#' @importFrom lubridate year as_date +#' @importFrom mapfactory format_fr_pct +#' @importFrom scales label_number +#' @importFrom tidyr gather #' #' @export #' #' @examples -#' creer_graphe_3_1(millesime_obs_artif_gk3 = 2019,millesime_population = 2018) - - -creer_graphe_3_1 <- function(millesime_obs_artif_gk3,millesime_population){ - - - - millesime_debut <- millesime_obs_artif_gk3 - 9 - - - # Creation de la table utile a la production du graphique - evol_artif <- observatoire_artificialisation_gk3 %>% - dplyr::mutate(date=year(.data$date)) %>% - dplyr::filter((.data$TypeZone == "D\u00e9partements" & .data$CodeZone %in% c("44","49","53","72","85")) | - (.data$TypeZone == "R\u00e9gions" & .data$CodeZone =="52"), - .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_artificialisation=round(((sum(.data$surface_artificialisee[which(date==millesime_obs_artif_gk3)],na.rm=T) / sum(.data$surface_artificialisee[which(date==millesime_obs_artif_gk3-9)],na.rm=T))-1)*100,2)) %>% - dplyr::ungroup() %>% - dplyr::mutate(CodeZone= as.character(CodeZone), - CodeZone = replace(CodeZone, CodeZone=="52","Région")) %>% - dplyr::select (CodeZone,evolution_artificialisation) +#' creer_graphe_1_6(millesime_ocsge = 2016) - evol_artif <- evol_artif %>% - tidyr::spread(key=CodeZone,value=evolution_artificialisation,fill=0) - cat <- data.frame(x = "surfaces artificialisees (hors routes)") - evol_artif <- cbind(cat,evol_artif) - evol_popul <- population_legale %>% - dplyr::mutate(date=year(.data$date)) %>% - dplyr::filter((.data$TypeZone == "D\u00e9partements" & .data$CodeZone %in% c("44","49","53","72","85")) | - (.data$TypeZone == "R\u00e9gions" & .data$CodeZone =="52"), - .data$date == millesime_population | .data$date == millesime_population - 9) %>% - dplyr::group_by(.data$TypeZone,.data$Zone,.data$CodeZone) %>% - summarise(evolution_population=round(((sum(.data$population_municipale[which(date==millesime_population)],na.rm=T) / sum(.data$population_municipale[which(date==millesime_population-9)],na.rm=T))-1)*100,2)) %>% - dplyr::ungroup() %>% - dplyr::mutate(CodeZone= as.character(CodeZone), - CodeZone = replace(CodeZone, CodeZone=="52","Région")) %>% - dplyr::select (CodeZone,evolution_population) +creer_graphe_1_6 <- function(millesime_ocsge = NULL){ - evol_popul <- evol_popul %>% - tidyr::spread(key=CodeZone,value=evolution_population,fill=0) - cat <- data.frame(x = "population municipale") - evol_popul <- cbind(cat,evol_popul) + # preparation des donnees + ocsge2 <- ocsge %>% + dplyr::mutate(date=lubridate::year(lubridate::as_date(.data$date)), + espace_naturel= autre_surface_naturelle + surface_en_eau + surface_naturelle_boisee) %>% + dplyr::filter(.data$date == millesime_ocsge) %>% + dplyr::select (.data$TypeZone,.data$Zone,.data$CodeZone, + .data$date,.data$espace_naturel, + .data$espace_agricole,.data$espace_artificialise) - data <- bind_rows(evol_artif,evol_popul) + # preparation graphiques + data1 <- ocsge2 %>% + dplyr::filter(.data$TypeZone == "Départements") %>% + tidyr::gather(variable,valeur,.data$espace_naturel:.data$espace_artificialise)%>% + dplyr::group_by(.data$TypeZone,.data$Zone,.data$CodeZone,.data$date) %>% + dplyr::summarise(variable=.data$variable,valeur=.data$valeur, taux=.data$valeur / sum(.data$valeur,na.rm=T)*100) %>% + dplyr::ungroup() - graph_3_1<-ggradar::ggradar( - data, - base.size = 1, - values.radar = c("0%", "10%", "20%"), - grid.min = 0, grid.mid = 10, grid.max = 20, - group.line.width = 1, - group.point.size = 5, - background.circle.colour = "blue", - background.circle.transparency = 0.1, - group.colours = c("#00AFBB", "#E7B800"), - axis.line.colour = "gray60", - gridline.min.colour = "gray60", - gridline.mid.colour = "gray60", - gridline.max.colour = "gray60", - legend.position = "top" -)+ - ggplot2::labs( - title = glue::glue("Taux de croissance compar\u00e9s\n{millesime_debut}/{millesime_obs_artif_gk3} (%)"), - subtitle = "<span style = 'color:#00AFBB'>surfaces artificialis\u00e9es (hors routes)</span> et <span style = 'color:#E7B800'>population municipale</span>", - caption = glue::glue("Source : Observatoire artificialisation {millesime_obs_artif_gk3} / Insee"))+ - ggplot2::theme( - legend.position = "none", - plot.subtitle = ggtext::element_markdown(size = 16, lineheight = 1.8), - plot.caption = ggtext::element_markdown(size = 12, lineheight = 1.8)) + # graphique pourcentages + graph_1_6a <- data1 %>% + ggplot2::ggplot() + + ggplot2::aes(x = .data$Zone, y = .data$taux, group = .data$variable, color = .data$variable) + + ggplot2::geom_point(size = 2, position = ggplot2::position_dodge(width = 0.5)) + + ggplot2::aes(x = .data$Zone, ymin = 0, ymax = .data$taux, group = .data$variable, color = .data$variable) + + ggplot2::geom_linerange(size = 1.2, position = ggplot2::position_dodge(width = 0.5)) + + ggplot2::aes(label = mapfactory::format_fr_pct(.data$taux, dec = 1)) + + ggplot2::geom_label( + position = ggplot2::position_dodge(width = 0.5), + vjust = 0.5, hjust = -0.5 + ) + + ggplot2::coord_flip() + + ggplot2::scale_y_continuous( + # breaks = seq(0, max(data1$taux) * 1.2, by = 10), + # minor_breaks = NULL, + limits = c(0, max(data1$taux) * 1.2), + labels = scales::label_number(big.mark = " ", decimal.mark = ",", suffix = " %"), + expand = c(0,0) + ) + + ggplot2::labs( + title = "R\u00e9partition des surfaces entre <span style = 'color:#2E8B57'>espaces naturels </span> <br><span style = 'color:#FF9940'>espaces artificialis\u00e9s </span> et <span style = 'color:#5770BE'>espaces agricoles</span>", + subtitle = glue::glue("en {millesime_ocsge}, en %"), + caption = glue::glue("Source : OCSGE {millesime_ocsge}"), + x = NULL, y = NULL + ) + + ggplot2::theme( + panel.grid.major.y = ggplot2::element_blank(), + legend.position = "none", + plot.title = ggtext::element_textbox_simple(size = 14, lineheight = 1, hjust = 0), + plot.subtitle = ggplot2::element_text(size = 12), + plot.caption = ggplot2::element_text(size = 10), + ) + + ggplot2::scale_color_manual(values = c("#5770BE", "#FF9940","#2E8B57")) + return(graph_1_6a) - return(graph_3_1) }