diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e7311ac86e1c3bb8caaa7c3f5f2e438f7d28b63c..fd5d66b3fcecba3b8501e22e8176909eb738bc8a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: rocker/geospatial:4.0.1 +image: rocker/geospatial:latest variables: R_LIBS_USER: "ci/lib" @@ -17,11 +17,12 @@ stages: building: stage: build + allow_failure: true script: - mkdir -p -m777 $R_LIBS_USER - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));remotes::install_deps(dependencies = TRUE, upgrade = "always")' - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));remotes::install_cran(c("pkgdown", "DT"), upgrade = "always")' - - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));devtools::check()' + - Rscript -e '.libPaths(c(Sys.getenv("R_LIBS_USER"), .libPaths()));devtools::check(error_on = "error")' # To have the coverage percentage appear as a gitlab badge follow these # instructions: diff --git a/DESCRIPTION b/DESCRIPTION index 939f2fe3463511e14b9d3ca68f2bf6e71ab02411..4c279225f97ac977f708db6efcebceeade1061c8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: propre.artificialisation Title: Publication template on land use -Version: 0.0.0.9000 +Version: 0.0.0.9001 Authors@R: c( person("Daniel", "Kalioudjoglou", , "daniel.kalioudjoglou@developpement-durable.gouv.fr", role = "aut"), person("Franck", "Gaspard", , "franck.gaspard@developpement-durable.gouv.fr", role = "aut"), @@ -36,15 +36,14 @@ Imports: stringr, tibble, tidyr, - tricky, - utils + tricky Suggests: rmarkdown, testthat (>= 3.0.0) VignetteBuilder: knitr Remotes: - gitlab::dreal-datalab/mapfactory, + git::https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/mapfactory.git, maeltheuliere/COGiter, pachevalier/tricky, spyrales/gouvdown @@ -53,4 +52,4 @@ Encoding: UTF-8 LazyData: true LazyDataCompression: bzip2 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 diff --git a/R/creer_carte_1_3.R b/R/creer_carte_1_3.R index bfc4d21e220a9a64cf213df8bfccfec396ee1ccf..c705154dac41e3ce82a7660442f7c2b8673933ab 100644 --- a/R/creer_carte_1_3.R +++ b/R/creer_carte_1_3.R @@ -16,7 +16,7 @@ #' @export #' #' @examples -#' creer_carte_1_3(millesime_ocsge=2016, code_reg = '52') +#' creer_carte_1_3(millesime_ocsge = 2016, code_reg = '52') creer_carte_1_3 <- function(millesime_ocsge,code_reg){ @@ -34,9 +34,9 @@ creer_carte_1_3 <- function(millesime_ocsge,code_reg){ if (code_reg %in% c('52')) { 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) + dplyr::select("TypeZone","Zone","CodeZone","date","espace_artificialise") %>% + dplyr::mutate(valeur_ind = round(.data$espace_artificialise / 10000, 0)) %>% + dplyr::select(-"espace_artificialise") mois <- lubridate::month(data[1,"date"],label=TRUE) @@ -50,7 +50,7 @@ creer_carte_1_3 <- function(millesime_ocsge,code_reg){ carte_1_3 <- mapfactory::creer_carte_communes_prop(data = data, code_region = code_reg, carto = fond_carto, - indicateur = valeur, + indicateur = valeur_ind, pourcent = FALSE, decimales=0, palette = "pal_gouv_h", diff --git a/R/creer_carte_1_7.R b/R/creer_carte_1_7.R index 18ada4c5d33d982c550fd36a036acff1b4705659..7aa912107f53ae01eaf168433c4881dc6234ad39 100644 --- a/R/creer_carte_1_7.R +++ b/R/creer_carte_1_7.R @@ -49,21 +49,21 @@ creer_carte_1_7 <- function(millesime_ocsge, 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) + dplyr::select("TypeZone","CodeZone","Zone","date","valeur") %>% + dplyr::mutate(valeur_ind =.data$valeur * 100) nom_region <- COGiter::regions %>% - dplyr::filter (.data$REG == code_reg) %>% + dplyr::filter(.data$REG == code_reg) %>% dplyr::mutate(NCCENR = as.character(forcats::fct_drop(.data$NCCENR))) %>% dplyr::pull(.data$NCCENR) fond_carto <- mapfactory::fond_carto(nom_reg = nom_region) - bins <- stats::quantile(data$valeur,probs = c(0,0.1, 0.25, 0.5,0.75,0.9,1),na.rm=TRUE) + bins <- stats::quantile(data$valeur_ind, probs = c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1), na.rm=TRUE) carte_1_7 <- mapfactory::creer_carte_communes(data = data, code_region=code_reg, carto = fond_carto, - indicateur = valeur, + indicateur = valeur_ind, bornes = bins, pourcent = TRUE, decimales = 1, diff --git a/R/creer_carte_2_2.R b/R/creer_carte_2_2.R index 5876088ef2ac2af4c30d348e2abd135ca9dc5bd7..19d3df9d5b00c26ad04d05502da6a4802c9326d1 100644 --- a/R/creer_carte_2_2.R +++ b/R/creer_carte_2_2.R @@ -30,7 +30,7 @@ creer_carte_2_2 <- function(millesime_obs_artif) { 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::select("CodeZone", "TypeZone", "Zone", "date", "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 @@ -42,7 +42,7 @@ creer_carte_2_2 <- function(millesime_obs_artif) { # 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) + dplyr::select("name") bbox_reg <- sf::st_bbox(sf::st_buffer(data, 50000)) diff --git a/R/creer_carte_2_7.R b/R/creer_carte_2_7.R index 4aa04eb6c072da12c852d0b5e810de8a3de3600d..52f34b402d987b9fa838497b45b0d7d73a86d7bc 100644 --- a/R/creer_carte_2_7.R +++ b/R/creer_carte_2_7.R @@ -43,7 +43,7 @@ creer_carte_2_7 <- function(millesime_obs_artif= NULL, code_reg = NULL) { .data$date >= millesime_obs_artif - 9) %>% dplyr::mutate(flux_naf_artificialisation_total = .data$flux_naf_artificialisation_total / 10000) %>% dplyr::group_by(.data$CodeZone, .data$TypeZone, .data$Zone) %>% - dplyr::summarise(valeur = sum(.data$flux_naf_artificialisation_total, na.rm = T)) %>% + dplyr::summarise(valeur_ind = sum(.data$flux_naf_artificialisation_total, na.rm = T)) %>% dplyr::ungroup() nom_region <- COGiter::regions %>% @@ -54,13 +54,13 @@ creer_carte_2_7 <- function(millesime_obs_artif= NULL, code_reg = NULL) { fond_cartographique <- mapfactory::fond_carto(nom_reg = nom_region) # bins <- stats::quantile(data$valeur,probs = c(0,0.1, 0.25, 0.5,0.75,0.9,1),na.rm=TRUE) # bins <- stats::quantile(data$valeur,probs = c(0,0.2, 0.4, 0.6,0.8,1),na.rm=TRUE) - bins <- stats::quantile(data$valeur,probs = c(0, 0.25, 0.50, 0.75, 1), na.rm=TRUE) + bins <- stats::quantile(data$valeur_ind, probs = c(0, 0.25, 0.50, 0.75, 1), na.rm=TRUE) carte_2_7 <- mapfactory::creer_carte_communes(data = data, code_region=code_reg, carto = fond_cartographique, - indicateur = valeur, + indicateur = valeur_ind, bornes = bins, decimales = 1, palette = "pal_gouv_h", diff --git a/R/creer_carte_2_8.R b/R/creer_carte_2_8.R index f4f52beb16c84d8a78c25ea4966e3b6133f97621..6845bb2bc2b70b2d2e41f92020dd28143d5bef12 100644 --- a/R/creer_carte_2_8.R +++ b/R/creer_carte_2_8.R @@ -21,8 +21,7 @@ #' @examples #' creer_carte_2_8(millesime_stock_artif = 2020, code_reg = 52) #' -creer_carte_2_8 <- function(millesime_stock_artif = NULL, - code_reg = NULL) { +creer_carte_2_8 <- function(millesime_stock_artif = NULL, code_reg = NULL) { 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(code_reg, is.null, msg = "code_reg n\'est pas renseign\u00e9") @@ -44,31 +43,31 @@ creer_carte_2_8 <- function(millesime_stock_artif = NULL, COGiter::filtrer_cog(reg = code_reg) %>% dplyr::filter(.data$TypeZone =="Communes", .data$date == millesime_stock_artif | .data$date == millesime_debut) %>% - dplyr::select (-.data$surf_cadastree) %>% + dplyr::select(-"surf_cadastree") %>% dplyr::arrange(.data$TypeZone, .data$Zone, .data$CodeZone, .data$date) %>% dplyr::group_by(.data$TypeZone, .data$Zone, .data$CodeZone) %>% - dplyr::mutate(valeur = round(.data$surface_artificialisee * 100 / dplyr::lag(.data$surface_artificialisee) - 100, 1)) %>% + dplyr::mutate(valeur_ind = round(.data$surface_artificialisee * 100 / dplyr::lag(.data$surface_artificialisee) - 100, 1)) %>% dplyr::ungroup() %>% dplyr::filter(.data$date == millesime_stock_artif) %>% - dplyr::select(.data$TypeZone, .data$CodeZone, .data$Zone, .data$valeur) + dplyr::select("TypeZone", "CodeZone", "Zone", "valeur_ind") nom_region <- COGiter::regions %>% - dplyr::filter (.data$REG == code_reg) %>% + dplyr::filter(.data$REG == code_reg) %>% dplyr::mutate(NCCENR = as.character(forcats::fct_drop(.data$NCCENR))) %>% - dplyr::pull(.data$NCCENR) + dplyr::pull("NCCENR") fond_cartographique <- mapfactory::fond_carto(nom_reg = nom_region) # p <- c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1) # p <- c(0.30, 0.55, 0.75, 0.9, 1) p <- c(0.1, 0.25, 0.5, 0.75, 0.9) - bins <- stats::quantile(data$valeur, probs = p, na.rm=TRUE) + bins <- stats::quantile(data$valeur_ind, probs = p, na.rm=TRUE) carte_2_8 <- mapfactory::creer_carte_communes(data = data, - code_region=code_reg, + code_region = code_reg, carto = fond_cartographique, - indicateur = valeur, + indicateur = valeur_ind, bornes = bins, decimales = 1, palette = "pal_gouv_h", diff --git a/R/creer_graphe_1_1.R b/R/creer_graphe_1_1.R index 12f64c884cafb3f343f189f3e63620e869ba6586..4d00a1d2522b904ce14d627202b5dbab7d146bfa 100644 --- a/R/creer_graphe_1_1.R +++ b/R/creer_graphe_1_1.R @@ -63,7 +63,7 @@ creer_graphe_1_1 <- function(code_reg = NULL){ .data$codezone==code_reg~ 1, TRUE ~ 0) ) %>% - dplyr::select(.data$zone,.data$taux_artificialisation,.data$part_dans_surface_nationale,.data$couleur_barre) + dplyr::select("zone", "taux_artificialisation", "part_dans_surface_nationale", "couleur_barre") valeur_max <- max(data$taux_artificialisation,na.rm=T) diff --git a/R/creer_graphe_1_4.R b/R/creer_graphe_1_4.R index beb472de0a9f2c7111b8dcf8ed6ce92d5a54ff36..3552eb08220a830a5fd3c33b2a083f2482b05f78 100644 --- a/R/creer_graphe_1_4.R +++ b/R/creer_graphe_1_4.R @@ -5,12 +5,12 @@ #' #' @return Un diagramme en barres #' -#' @importFrom dplyr filter select mutate group_by desc arrange case_when +#' @importFrom dplyr filter select mutate group_by desc arrange case_when pull #' @importFrom COGiter filtrer_cog #' @importFrom forcats fct_inorder fct_drop #' @importFrom ggplot2 ggplot aes scale_y_continuous theme geom_text geom_col scale_fill_manual scale_x_discrete coord_flip #' @importFrom glue glue -#' @importFrom lubridate make_date +#' @importFrom lubridate make_date year #' @importFrom tidyr spread gather #' @importFrom tricky set_standard_names #' @importFrom ggtext element_markdown @@ -25,10 +25,10 @@ creer_graphe_1_4 <- function(code_reg){ millesime_teruti <- teruti %>% - dplyr::select(date) %>% + dplyr::select("date") %>% # unique() %>% - pull() %>% - year() %>% + dplyr::pull() %>% + lubridate::year() %>% max() attempt::stop_if(millesime_teruti, is.null, msg = "millesime_teruti n'est pas renseign\u00e9") @@ -53,20 +53,20 @@ creer_graphe_1_4 <- function(code_reg){ dplyr::arrange(.data$typezone,.data$zone) %>% dplyr::mutate(zone = forcats::fct_drop(.data$zone) %>% forcats::fct_inorder(), voiries=.data$sols_revetus, - hors_voiries=(.data$sols_batis+ .data$sols_stabilises+ .data$autres_sols_artificialises ) + hors_voiries=(.data$sols_batis + .data$sols_stabilises + .data$autres_sols_artificialises ) ) %>% - dplyr::select(.data$typezone,.data$codezone,.data$zone,.data$voiries,.data$hors_voiries)%>% - tidyr::gather(variable,valeur,.data$voiries:.data$hors_voiries)%>% - dplyr::mutate(variable = replace(.data$variable, .data$variable=="hors_voiries","surfaces artificialis\u00e9es hors voiries"))%>% - dplyr::mutate(variable=factor(.data$variable,levels=c("surfaces artificialis\u00e9es hors voiries","voiries"))%>% forcats::fct_inorder()) %>% + dplyr::select("typezone", "codezone", "zone", "voiries", "hors_voiries")%>% + tidyr::gather("variable", "valeur", .data$voiries:.data$hors_voiries)%>% + dplyr::mutate(variable = replace(.data$variable, .data$variable == "hors_voiries", "surfaces artificialis\u00e9es hors voiries"))%>% + dplyr::mutate(variable = factor(.data$variable, levels = c("surfaces artificialis\u00e9es hors voiries","voiries")) %>% forcats::fct_inorder()) %>% dplyr::group_by(.data$typezone,.data$codezone,.data$zone) %>% dplyr::arrange(.data$codezone, dplyr::desc(.data$variable))%>% dplyr::mutate(position = cumsum(.data$valeur) - 0.5 * .data$valeur) - graph_1_4<-data %>% + graph_1_4 <- data %>% ggplot2::ggplot(ggplot2::aes(x=.data$zone,y=.data$valeur)) + - ggplot2::geom_col(ggplot2::aes(fill = .data$variable), width = 0.9)+ - ggplot2::geom_text(ggplot2::aes(y = .data$position, label = mapfactory::format_fr(.data$valeur,0), group =.data$variable), color = "white", size=3)+ + ggplot2::geom_col(ggplot2::aes(fill = .data$variable), width = 0.9) + + ggplot2::geom_text(ggplot2::aes(y = .data$position, label = mapfactory::format_fr(.data$valeur,0), group =.data$variable), color = "white", size=3) + ggplot2::labs(title= glue::glue("Etat des surfaces artificialis\u00e9es en {millesime_teruti} (en hectares)"), subtitle=glue::glue("<span style = 'color:{couleur_hors_voirie}'> Hors voiries</span> et <span style = 'color:{couleur_voirie}'> en voiries</span>"), x="", @@ -74,11 +74,11 @@ creer_graphe_1_4 <- function(code_reg){ fill="", caption = glue::glue("Source : Teruti-Lucas {millesime_teruti}"))+ ggplot2::theme(legend.position = "none", - plot.subtitle = ggtext::element_markdown(size = 12, lineheight = 1.2))+ - ggplot2::scale_y_continuous(labels = scales::number_format(suffix = "", accuracy = 1)) + + plot.subtitle = ggtext::element_markdown(size = 12, lineheight = 1.2)) + + ggplot2::scale_y_continuous(labels = scales::number_format(suffix = "", accuracy = 1)) + ggplot2::coord_flip() + - ggplot2::scale_x_discrete(limits=rev) + - ggplot2::scale_fill_manual(values = c(couleur_voirie,couleur_hors_voirie)) + ggplot2::scale_x_discrete(limits = rev) + + ggplot2::scale_fill_manual(values = c(couleur_voirie, couleur_hors_voirie)) return(graph_1_4) diff --git a/R/creer_graphe_1_5.R b/R/creer_graphe_1_5.R index cf402155d18d4d67ca70ac4c460a84bef65e33a0..442c83c54b7da95c3c09f23a85ef199a5cf05ded 100644 --- a/R/creer_graphe_1_5.R +++ b/R/creer_graphe_1_5.R @@ -55,7 +55,7 @@ creer_graphe_1_5 <- function(code_reg){ voiries=(.data$sols_revetus )/.data$tous_sols*100, hors_voiries=(.data$sols_batis+ .data$sols_stabilises+ .data$autres_sols_artificialises )/.data$tous_sols*100 ) %>% - dplyr::select(.data$typezone,.data$codezone,.data$zone,.data$voiries,.data$hors_voiries)%>% + dplyr::select("typezone", "codezone", "zone", "voiries", "hors_voiries")%>% tidyr::gather(variable,valeur,.data$voiries:.data$hors_voiries)%>% dplyr::mutate(variable = replace(.data$variable, .data$variable=="hors_voiries","surfaces artificialis\u00e9es hors voiries"))%>% dplyr::mutate(variable=factor(.data$variable,levels=c("surfaces artificialis\u00e9es hors voiries","voiries"))%>% forcats::fct_inorder()) %>% @@ -63,7 +63,7 @@ creer_graphe_1_5 <- function(code_reg){ dplyr::arrange(.data$codezone, dplyr::desc(.data$variable)) %>% dplyr::mutate(position = cumsum(.data$valeur) - 0.5 * .data$valeur) - graph_1_5<-data %>% + graph_1_5 <- data %>% ggplot2::ggplot(ggplot2::aes(x=.data$zone,y=.data$valeur)) + ggplot2::geom_col(ggplot2::aes(fill = .data$variable), width = 0.9)+ ggplot2::geom_text(ggplot2::aes(y = .data$position, label = mapfactory::format_fr(.data$valeur,1,pourcent = TRUE), group =.data$variable), color = "white", size=3)+ diff --git a/R/creer_graphe_1_6.R b/R/creer_graphe_1_6.R index bffe0d1fb8d667bc0455720a2623d5b9c38e17d5..bcca7de8efe446599e92b4b3c38e41726ad0aff8 100644 --- a/R/creer_graphe_1_6.R +++ b/R/creer_graphe_1_6.R @@ -65,15 +65,15 @@ creer_graphe_1_6 <- function(millesime_ocsge = NULL, millesime_population = NULL TRUE ~ "") ) %>% dplyr::rename ("population_n"="population_municipale") %>% - dplyr::select (-.data$date) + dplyr::select(-"date") # table des seuils seuil_population <- population %>% - dplyr::select (.data$CodeZone,.data$seuil_pop) + dplyr::select("CodeZone", "seuil_pop") # population du millesime population_n <- population %>% - dplyr::select (.data$seuil_pop,.data$seuil_code, .data$population_n) %>% + dplyr::select("seuil_pop", "seuil_code", "population_n") %>% dplyr::group_by(.data$seuil_pop,.data$seuil_code) %>% dplyr::summarise(population_n = sum(.data$population_n, na.rm = T)) %>% dplyr::ungroup() diff --git a/R/creer_graphe_2_3.R b/R/creer_graphe_2_3.R index 721f8478fc3221c45a1ba9464df5633be52dc7bd..23037f45e904aa0bfaeb315991ba34cceb9ee313 100644 --- a/R/creer_graphe_2_3.R +++ b/R/creer_graphe_2_3.R @@ -31,18 +31,18 @@ creer_graphe_2_3 <- function(millesime_obs_artif,code_reg = NULL){ dplyr::mutate(date = as.character(lubridate::year(.data$date - 1))) %>% dplyr::filter(.data$TypeZone == "R\u00e9gions", !(.data$CodeZone %in% c("01","02","03","04","06"))) %>% - dplyr::select(.data$CodeZone, .data$TypeZone, .data$Zone, .data$date, .data$flux_naf_artificialisation_total) %>% + dplyr::select("CodeZone", "TypeZone", "Zone", "date", "flux_naf_artificialisation_total") %>% dplyr::mutate(flux_naf_artificialisation_total = .data$flux_naf_artificialisation_total / 10000) %>% 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(`evolution` = sum(.data$flux_naf_artificialisation_total, na.rm = T)) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$CodeZone,.data$evolution) %>% + dplyr::select("TypeZone", "Zone", "CodeZone", "evolution") %>% dplyr::mutate(couleur_barre = dplyr::case_when( - .data$CodeZone==code_reg~ 1, + .data$CodeZone == code_reg ~ 1, TRUE ~ 0)) - valeur_max <- max(data$evolution,na.rm=T) + valeur_max <- max(data$evolution, na.rm = TRUE) millesime_debut <- millesime_obs_artif - 10 graph_2_3<-data %>% diff --git a/R/creer_graphe_2_4.R b/R/creer_graphe_2_4.R index 3cbdfb52519854aa10149286d1315587e00678f5..66a67908060e5698c0325fc055a1f2b56353a064 100644 --- a/R/creer_graphe_2_4.R +++ b/R/creer_graphe_2_4.R @@ -42,7 +42,7 @@ creer_graphe_2_4 <- function(millesime_obs_artif = NULL, code_reg = NULL) { dplyr::filter(.data$TypeZone == "D\u00e9partements") %>% dplyr::arrange(.data$CodeZone) %>% dplyr::mutate(Zone=factor(.data$Zone) %>% forcats::fct_inorder())%>% - dplyr::select(.data$Zone, .data$date, .data$flux_naf_artificialisation_total) %>% + dplyr::select("Zone", "date", "flux_naf_artificialisation_total") %>% dplyr::mutate( Zone = forcats::fct_drop(.data$Zone), flux_naf_artificialisation_total = .data$flux_naf_artificialisation_total / 10000 diff --git a/R/creer_graphe_2_5.R b/R/creer_graphe_2_5.R index d79b17e95fdf57c706be215d6a2424bfe3461029..e6f8d697b8bb01da9a9441ba34c0f259d892b48d 100644 --- a/R/creer_graphe_2_5.R +++ b/R/creer_graphe_2_5.R @@ -41,7 +41,7 @@ creer_graphe_2_5 <- function(millesime_obs_artif=NULL, code_reg = NULL) { dplyr::filter(.data$TypeZone == "D\u00e9partements") %>% dplyr::arrange(.data$CodeZone) %>% dplyr::mutate(Zone=factor(.data$Zone) %>% forcats::fct_inorder())%>% - dplyr::select(.data$Zone, .data$date, .data$flux_naf_artificialisation_activite, .data$flux_naf_artificialisation_habitation, .data$flux_naf_artificialisation_mixte) %>% + dplyr::select("Zone", "date", "flux_naf_artificialisation_activite", "flux_naf_artificialisation_habitation", "flux_naf_artificialisation_mixte") %>% dplyr::mutate(Zone = forcats::fct_drop(.data$Zone)) %>% dplyr::arrange(.data$Zone) %>% dplyr::mutate(date = as.character(lubridate::year(.data$date - 1))) %>% diff --git a/R/creer_graphe_2_6.R b/R/creer_graphe_2_6.R index 195ecc3bc772eed567184c54beb248d1a207b9b3..143f24f3e957cc5290d88ab37d3b50404a4f1732 100644 --- a/R/creer_graphe_2_6.R +++ b/R/creer_graphe_2_6.R @@ -67,15 +67,15 @@ creer_graphe_2_6 <- function(millesime_stock_artif = NULL, millesime_population TRUE ~ "") ) %>% dplyr::rename ("population_n"="population_municipale") %>% - dplyr::select (-.data$date) + dplyr::select(-"date") # table des seuils seuil_population <- population %>% - dplyr::select (.data$CodeZone, .data$seuil_pop) + dplyr::select ("CodeZone", "seuil_pop") # population du millesime population_n <- population %>% - dplyr::select (.data$seuil_pop, .data$seuil_code, .data$population_n) %>% + dplyr::select("seuil_pop", "seuil_code", "population_n") %>% dplyr::group_by(.data$seuil_pop, .data$seuil_code) %>% dplyr::summarise(population_n = sum(.data$population_n, na.rm = T)) %>% dplyr::ungroup() @@ -89,7 +89,7 @@ creer_graphe_2_6 <- function(millesime_stock_artif = NULL, millesime_population dplyr::filter(.data$TypeZone == "Communes") %>% dplyr::mutate(date = lubridate::year(.data$date)) %>% dplyr::filter(.data$date == millesime_stock_artif | .data$date == millesime_debut) %>% - dplyr::select (-.data$surf_cadastree) %>% + dplyr::select(-"surf_cadastree") %>% dplyr::group_by(.data$seuil_pop,.data$date) %>% dplyr::summarise(surface_artificialisee = sum(.data$surface_artificialisee, na.rm = T)) %>% dplyr::ungroup() %>% @@ -102,7 +102,7 @@ creer_graphe_2_6 <- function(millesime_stock_artif = NULL, millesime_population glue::glue("communes entre\n",pop_2," et ",pop_3, " habitants"), glue::glue("communes de plus\nde ",pop_3," habitants"))) %>% forcats::fct_rev()) %>% - dplyr::select(.data$seuil_pop,.data$evolution) + dplyr::select("seuil_pop", "evolution") valeur_max <- max(data$evolution, na.rm = T) diff --git a/R/creer_graphe_3_1.R b/R/creer_graphe_3_1.R index 6c74c4d529a34e34df88a4d7f193cbb93be24546..3311cf10e0cc71fc344a7ab301e6c4cdf1690155 100644 --- a/R/creer_graphe_3_1.R +++ b/R/creer_graphe_3_1.R @@ -53,13 +53,13 @@ creer_graphe_3_1 <- function(millesime_stock_artif = NULL, COGiter::filtrer_cog(reg = code_reg) %>% dplyr::filter(.data$TypeZone %in% c("France","R\u00e9gions", "D\u00e9partements"), .data$date == millesime_stock_artif | .data$date == millesime_debut) %>% - dplyr::select (-.data$surf_cadastree) %>% + dplyr::select(-"surf_cadastree") %>% dplyr::arrange(.data$TypeZone, .data$Zone, .data$CodeZone, .data$date) %>% dplyr::group_by(.data$TypeZone, .data$Zone, .data$CodeZone) %>% dplyr::mutate(evolution_artificialisation = round(.data$surface_artificialisee * 100 / dplyr::lag(.data$surface_artificialisee) - 100, 1)) %>% dplyr::ungroup() %>% dplyr::filter(.data$date == millesime_stock_artif) %>% - dplyr::select(.data$TypeZone, .data$CodeZone, .data$Zone, .data$evolution_artificialisation) + dplyr::select("TypeZone", "CodeZone", "Zone", "evolution_artificialisation") evol_popul <- population_legale %>% @@ -72,7 +72,7 @@ creer_graphe_3_1 <- function(millesime_stock_artif = NULL, dplyr::mutate(evolution_population = round(.data$population_municipale * 100 / dplyr::lag(.data$population_municipale) - 100, 1)) %>% dplyr::ungroup() %>% dplyr::filter(.data$date == millesime_population) %>% - dplyr::select(.data$TypeZone, .data$CodeZone, .data$Zone, .data$evolution_population) + dplyr::select("TypeZone", "CodeZone", "Zone", "evolution_population") data <- dplyr::full_join(evol_artif, evol_popul) %>% diff --git a/R/creer_graphe_3_3.R b/R/creer_graphe_3_3.R index 9e533789977537fc886cd55041c933d09b26fb3f..e720a5487036027d3f5f6ec56eda94b9bd43dc60 100644 --- a/R/creer_graphe_3_3.R +++ b/R/creer_graphe_3_3.R @@ -68,16 +68,16 @@ creer_graphe_3_3 <- function(millesime_stock_artif = NULL, millesime_population TRUE ~ "") ) %>% dplyr::rename ("population_n"="population_municipale") %>% - dplyr::select (-.data$date) + dplyr::select(-"date") # table des seuils seuil_population <- population %>% - dplyr::select (.data$CodeZone,.data$seuil_pop) + dplyr::select("CodeZone", "seuil_pop") # population du millesime population_n <- population %>% - dplyr::select (.data$seuil_pop,.data$seuil_code, .data$population_n) %>% - dplyr::group_by(.data$seuil_pop,.data$seuil_code) %>% + dplyr::select("seuil_pop","seuil_code", "population_n") %>% + dplyr::group_by(.data$seuil_pop, .data$seuil_code) %>% dplyr::summarise(population_n = sum(.data$population_n, na.rm = T)) %>% dplyr::ungroup() @@ -88,22 +88,22 @@ evol_artif <- stock_artificialise %>% dplyr::mutate(date = lubridate::year(.data$date)) %>% COGiter::filtrer_cog(reg = code_reg) %>% dplyr::filter(.data$TypeZone == "Communes", - .data$date == millesime_stock_artif | .data$date == millesime_debut) %>% - dplyr::select (-.data$surf_cadastree) + .data$date == millesime_stock_artif | .data$date == millesime_debut) %>% + dplyr::select(-"surf_cadastree") evol_artif1 <- evol_artif %>% dplyr::left_join(seuil_population) %>% dplyr::mutate(dep = substr(.data$CodeZone,1,2)) %>% - dplyr::filter (.data$date == millesime_stock_artif) %>% + dplyr::filter(.data$date == millesime_stock_artif) %>% dplyr::group_by(.data$dep, .data$seuil_pop, .data$date) %>% dplyr::summarise(surface_artificialisee = sum(.data$surface_artificialisee, na.rm = T)) %>% dplyr::ungroup() %>% dplyr::left_join(COGiter::departements %>% dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), + dplyr::select("DEP", "NOM_DEP"), by=c("dep"= "DEP")) %>% - dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::rename(Zone = "NOM_DEP") %>% + dplyr::select(-"dep") evol_artif1_2 <- evol_artif1 %>% dplyr::group_by(.data$seuil_pop,.data$date) %>% @@ -113,8 +113,8 @@ evol_artif1_2 <- evol_artif1 %>% dplyr::filter (.data$REG == code_reg) %>% dplyr::pull(.data$NOM_REG)) -evol_artif1 <-dplyr::bind_rows(evol_artif1,evol_artif1_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$date, .data$surface_artificialisee) +evol_artif1 <- dplyr::bind_rows(evol_artif1,evol_artif1_2) %>% + dplyr::select("seuil_pop", "Zone", "date", "surface_artificialisee") evol_artif2 <- evol_artif %>% dplyr::left_join(seuil_population) %>% @@ -125,10 +125,10 @@ evol_artif2 <- evol_artif %>% dplyr::ungroup() %>% dplyr::left_join(COGiter::departements %>% dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), - by=c("dep"= "DEP")) %>% + dplyr::select("DEP", "NOM_DEP"), + by = c("dep"= "DEP")) %>% dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::select(-"dep") evol_artif2_2 <- evol_artif2 %>% dplyr::group_by(.data$seuil_pop, .data$date) %>% @@ -138,8 +138,8 @@ evol_artif2_2 <- evol_artif2 %>% dplyr::filter (.data$REG == code_reg) %>% dplyr::pull(.data$NOM_REG)) -evol_artif2 <-dplyr::bind_rows(evol_artif2,evol_artif2_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$date, .data$surface_artificialisee) +evol_artif2 <-dplyr::bind_rows(evol_artif2, evol_artif2_2) %>% + dplyr::select("seuil_pop", "Zone", "date", "surface_artificialisee") evol_artif3 <- rbind(evol_artif1,evol_artif2) %>% #regroupement des annees dplyr::arrange(.data$seuil_pop, .data$Zone, .data$date) %>% @@ -147,7 +147,7 @@ evol_artif3 <- rbind(evol_artif1,evol_artif2) %>% #regroupement des annees dplyr::mutate(evolution_artificialisation = round(.data$surface_artificialisee * 100 / dplyr::lag(.data$surface_artificialisee) - 100, 1)) %>% dplyr::ungroup() %>% dplyr::filter(.data$date == millesime_stock_artif) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$evolution_artificialisation) + dplyr::select("seuil_pop", "Zone", "evolution_artificialisation") # preparation des donnees evol_population @@ -166,21 +166,21 @@ evol_popul1 <- evol_popul %>% dplyr::ungroup() %>% dplyr::left_join(COGiter::departements %>% dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), + dplyr::select("DEP", "NOM_DEP"), by=c("dep"= "DEP")) %>% dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::select(-"dep") evol_popul1_2 <- evol_popul1 %>% dplyr::group_by(.data$seuil_pop, .data$date) %>% dplyr::summarise(population_municipale = sum(.data$population_municipale, na.rm = T)) %>% dplyr::ungroup() %>% dplyr::mutate(Zone = COGiter::regions %>% - dplyr::filter (.data$REG == code_reg) %>% - dplyr::pull(.data$NOM_REG)) + dplyr::filter(.data$REG == code_reg) %>% + dplyr::pull("NOM_REG")) -evol_popul1 <-dplyr::bind_rows(evol_popul1,evol_popul1_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$date, .data$population_municipale) +evol_popul1 <-dplyr::bind_rows(evol_popul1, evol_popul1_2) %>% + dplyr::select("seuil_pop", "Zone", "date", "population_municipale") evol_popul2 <- evol_popul %>% dplyr::left_join(seuil_population) %>% @@ -191,10 +191,10 @@ evol_popul2 <- evol_popul %>% dplyr::ungroup() %>% dplyr::left_join(COGiter::departements %>% dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), + dplyr::select("DEP", "NOM_DEP"), by=c("dep"= "DEP")) %>% dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::select(-"dep") evol_popul2_2 <- evol_popul2 %>% dplyr::group_by(.data$seuil_pop, .data$date) %>% @@ -204,8 +204,8 @@ evol_popul2_2 <- evol_popul2 %>% dplyr::filter (.data$REG == code_reg) %>% dplyr::pull(.data$NOM_REG)) -evol_popul2 <-dplyr::bind_rows(evol_popul2,evol_popul2_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$date, .data$population_municipale) +evol_popul2 <- dplyr::bind_rows(evol_popul2 ,evol_popul2_2) %>% + dplyr::select("seuil_pop", "Zone", "date", "population_municipale") evol_popul3 <- rbind(evol_popul1,evol_popul2) %>% #regroupement des annees dplyr::arrange(.data$seuil_pop, .data$Zone, .data$date) %>% @@ -213,10 +213,10 @@ evol_popul3 <- rbind(evol_popul1,evol_popul2) %>% #regroupement des annees dplyr::mutate(evolution_population = round(.data$population_municipale * 100 / dplyr::lag(.data$population_municipale) - 100, 1)) %>% dplyr::ungroup() %>% dplyr::filter(.data$date == millesime_population) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$evolution_population) + dplyr::select("seuil_pop", "Zone", "evolution_population") data_final <- evol_artif3 %>% - dplyr::full_join(evol_popul3 %>% dplyr::select(.data$seuil_pop, .data$Zone, .data$evolution_population)) %>% + dplyr::full_join(evol_popul3 %>% dplyr::select("seuil_pop", "Zone", "evolution_population")) %>% dplyr::mutate(`Seuil de population` = factor(.data$seuil_pop, levels = c(glue::glue("communes de moins\nde ",pop_1," habitants"), glue::glue("communes entre\n",pop_1," et ",pop_2, " habitants"), glue::glue("communes entre\n",pop_2," et ",pop_3, " habitants"), diff --git a/R/creer_graphe_3_4.R b/R/creer_graphe_3_4.R index 78bf48cdbb9a61e8d27baa30334dc413ef30ed24..aab97399e9e90e0ef1c60d76ff67bb05d3a2df82 100644 --- a/R/creer_graphe_3_4.R +++ b/R/creer_graphe_3_4.R @@ -53,7 +53,7 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = dplyr::filter(((.data$TypeZone == "D\u00e9partements") | (.data$TypeZone == "R\u00e9gions")), .data$date == millesime_debut) %>% dplyr::mutate(surface_artificialisee = .data$surface_artificialisee) %>% - dplyr::select (-.data$surf_cadastree,-.data$date) %>% + dplyr::select (-"surf_cadastree", -"date") %>% dplyr::rename ("stock_depart"="surface_artificialisee") # preparation des flux @@ -62,13 +62,13 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = COGiter::filtrer_cog(reg = code_reg) %>% dplyr::filter(((.data$TypeZone == "D\u00e9partements") | (.data$TypeZone == "R\u00e9gions")), (.data$date == millesime_debut) |(.data$date == millesime_stock_artif)) %>% - dplyr::select (-.data$surf_cadastree) %>% + dplyr::select(-"surf_cadastree") %>% dplyr::arrange(.data$TypeZone, .data$Zone, .data$CodeZone, .data$date) %>% dplyr::group_by(.data$TypeZone, .data$Zone, .data$CodeZone) %>% dplyr::mutate(flux_artificialisation = .data$surface_artificialisee - dplyr::lag(.data$surface_artificialisee) ) %>% dplyr::ungroup() %>% dplyr::filter(.data$date == millesime_stock_artif) %>% - dplyr::select (-.data$date , -.data$surface_artificialisee) + dplyr::select(-"date", -"surface_artificialisee") # preparation des donnees population @@ -79,8 +79,8 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = .data$date == millesime_debut_population | .data$date == millesime_fin_population) popul_debut <- evol_popul %>% dplyr::filter(.data$date == millesime_debut_population) %>% - dplyr::rename ("population_debut"="population_municipale") %>% - dplyr::select (-.data$date) + dplyr::rename("population_debut"="population_municipale") %>% + dplyr::select(-"date") evol_popul <- evol_popul %>% dplyr::filter(.data$date %in% c(millesime_debut_population,millesime_fin_population)) %>% dplyr::arrange(.data$date) %>% @@ -88,7 +88,7 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = dplyr::mutate(evolution_population=.data$population_municipale - dplyr::lag(.data$population_municipale)) %>% dplyr::ungroup() %>% dplyr::filter(.data$date %in% c(millesime_fin_population)) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$CodeZone,.data$evolution_population) + dplyr::select("TypeZone", "Zone", "CodeZone", "evolution_population") data <- stock_depart %>% dplyr::left_join(flux) %>% @@ -97,7 +97,7 @@ creer_graphe_3_4 <- function(millesime_stock_artif = NULL,millesime_population = 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_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("TypeZone", "Zone", "surf_artif_par_hab_an_x", "surf_artif_par_nouv_hab_entre_x_y") %>% tidyr::gather(variable, valeur, 3:4) %>% 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")) %>% diff --git a/R/creer_graphe_4_2.R b/R/creer_graphe_4_2.R index 016ebf807b18b3bf36207710147f30fdd6cc88af..73c55c6b4674e69dd1f22ca7a33e7d152d19d3d9 100644 --- a/R/creer_graphe_4_2.R +++ b/R/creer_graphe_4_2.R @@ -73,16 +73,16 @@ creer_graphe_4_2 <- function(millesime_stock_artif = NULL,millesime_population = .data$population_municipale > 0 ~ "A", TRUE ~ "") ) %>% - dplyr::rename ("population_n"="population_municipale") %>% - dplyr::select (-.data$date) + dplyr::rename("population_n" = "population_municipale") %>% + dplyr::select(-"date") # table des seuils seuil_population <- population %>% - dplyr::select (.data$CodeZone,.data$seuil_pop) + dplyr::select("CodeZone", "seuil_pop") # population du dernier millesime population_n <- population %>% - dplyr::select (.data$seuil_pop,.data$seuil_code, .data$population_n) %>% + dplyr::select("seuil_pop", "seuil_code", "population_n") %>% dplyr::group_by(.data$seuil_pop,.data$seuil_code) %>% dplyr::summarise(population_n = sum(.data$population_n, na.rm = T)) %>% dplyr::ungroup() @@ -94,7 +94,7 @@ creer_graphe_4_2 <- function(millesime_stock_artif = NULL,millesime_population = dplyr::filter(.data$date == millesime_debut_population, .data$TypeZone =="Communes") %>% dplyr::left_join(seuil_population) %>% - dplyr::select (.data$seuil_pop, .data$population_municipale) %>% + dplyr::select("seuil_pop", "population_municipale") %>% dplyr::group_by(.data$seuil_pop) %>% dplyr::summarise(population_ancienne = sum(.data$population_municipale, na.rm = T)) %>% dplyr::ungroup() @@ -108,7 +108,7 @@ creer_graphe_4_2 <- function(millesime_stock_artif = NULL,millesime_population = dplyr::filter(.data$TypeZone == "Communes", .data$date == millesime_debut) %>% dplyr::left_join(seuil_population) %>% - dplyr::select (.data$seuil_pop, .data$surface_artificialisee) %>% + dplyr::select ("seuil_pop", "surface_artificialisee") %>% dplyr::group_by(.data$seuil_pop) %>% dplyr::summarise(stock_depart = sum(.data$surface_artificialisee, na.rm = T)) %>% dplyr::ungroup() @@ -128,7 +128,7 @@ creer_graphe_4_2 <- function(millesime_stock_artif = NULL,millesime_population = dplyr::group_by(.data$seuil_pop) %>% dplyr::mutate(flux = .data$surface_artificialisee - dplyr::lag(.data$surface_artificialisee) ) %>% dplyr::filter(.data$date == millesime_stock_artif) %>% - dplyr::select (.data$seuil_pop , .data$flux) + dplyr::select ("seuil_pop" , "flux") data <- population_n %>% @@ -138,10 +138,10 @@ creer_graphe_4_2 <- function(millesime_stock_artif = NULL,millesime_population = dplyr::mutate(seuil_pop=as.factor(.data$seuil_pop),seuil_code=as.factor(.data$seuil_code)) %>% dplyr::mutate(surf_artif_par_hab_an_x=.data$stock_depart / .data$population_ancienne *10000) %>% dplyr::mutate(surf_artif_par_nouv_hab_entre_x_y =.data$flux / (.data$population_n - .data$population_ancienne) *10000) %>% - dplyr::select (.data$seuil_pop,.data$seuil_code,.data$surf_artif_par_hab_an_x,.data$surf_artif_par_nouv_hab_entre_x_y) %>% + dplyr::select("seuil_pop", "seuil_code", "surf_artif_par_hab_an_x", "surf_artif_par_nouv_hab_entre_x_y") %>% tidyr::gather(variable, valeur, 3:4) %>% dplyr::arrange(desc(.data$seuil_code)) %>% - 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(seuil_pop = forcats::fct_drop(.data$seuil_pop) %>% forcats::fct_inorder()) @@ -156,8 +156,8 @@ creer_graphe_4_2 <- function(millesime_stock_artif = NULL,millesime_population = color = .data$variable), position = ggplot2::position_dodge(width=1), hjust=-0.1) + - ggplot2::scale_color_manual(values = c("#82534b","#FF8D7E")) + - ggplot2::scale_fill_manual(values = c("#82534b","#FF8D7E")) + + ggplot2::scale_color_manual(values = c("#82534b", "#FF8D7E")) + + ggplot2::scale_fill_manual(values = c("#82534b", "#FF8D7E")) + ggplot2::labs( title = glue::glue("Surfaces cadastr\u00e9es consomm\u00e9es (en 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> "), @@ -168,7 +168,7 @@ creer_graphe_4_2 <- function(millesime_stock_artif = NULL,millesime_population = ) + 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( legend.position = "none", diff --git a/R/creer_graphe_5_1.R b/R/creer_graphe_5_1.R index a1c372df036a34a808aa23074900003bad5fe193..1bbbaac402f0fa9869be4bfdccec7b1758c81c8c 100644 --- a/R/creer_graphe_5_1.R +++ b/R/creer_graphe_5_1.R @@ -39,13 +39,13 @@ creer_graphe_5_1 <- function(millesime_stock_artif,code_reg) { if (code_reg %in% c('52')) { data <- stock_artificialise %>% - dplyr::select (-.data$surf_cadastree) %>% + dplyr::select(-"surf_cadastree") %>% COGiter::filtrer_cog(reg = code_reg) %>% dplyr::mutate(date=lubridate::year(.data$date)) %>% dplyr::filter(.data$TypeZone %in% c("D\u00e9partements"), .data$date %in% c(millesime_stock_artif,millesime_reference)) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$CodeZone,.data$date,.data$surface_artificialisee) %>% + dplyr::select("TypeZone","Zone","CodeZone","date","surface_artificialisee") %>% dplyr::mutate(date = dplyr::case_when( .data$date == millesime_reference ~ "stock_mill_debut", .data$date == millesime_stock_artif ~ "stock_mill_fin", diff --git a/R/creer_graphe_5_2.R b/R/creer_graphe_5_2.R index 1043ebcfa2ea4218b1cb1029b515508126757d02..4307e7f8fd91f22705d20563b87a490570d585f8 100644 --- a/R/creer_graphe_5_2.R +++ b/R/creer_graphe_5_2.R @@ -35,7 +35,7 @@ creer_graphe_5_2 <- function(millesime_obs_artif,code_reg) { data <- observatoire_artificialisation %>% COGiter::filtrer_cog(reg = code_reg) %>% dplyr::filter(.data$TypeZone %in% c("R\u00e9gions","D\u00e9partements")) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$date,.data$flux_naf_artificialisation_total) %>% + dplyr::select( "TypeZone", "Zone", "date", "flux_naf_artificialisation_total") %>% dplyr::arrange(.data$TypeZone,.data$Zone,.data$date) %>% dplyr::mutate(simul=FALSE, flux_naf_artificialisation_total = .data$flux_naf_artificialisation_total / 10000) %>% @@ -82,7 +82,7 @@ creer_graphe_5_2 <- function(millesime_obs_artif,code_reg) { data_segment_departements = data_departements %>% dplyr::filter(.data$date ==max(date)) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$date,.data$valeur_objectif,.data$valeur_tendance) %>% + dplyr::select( "TypeZone", "Zone", "date", "valeur_objectif", "valeur_tendance") %>% dplyr::mutate(y = .data$valeur_objectif+0.5*(.data$valeur_tendance-.data$valeur_objectif), rank = rank(.data$y), nrow = max(dplyr::row_number()), @@ -92,7 +92,7 @@ creer_graphe_5_2 <- function(millesime_obs_artif,code_reg) { {mapfactory::format_fr_nb(valeur_tendance-valeur_objectif,0)} ha en moins \u00e0 r\u00e9aliser")) data_segment_region = data_region %>% dplyr::filter(.data$date ==max(date)) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$date,.data$valeur_objectif,.data$valeur_tendance) %>% + dplyr::select( "TypeZone", "Zone", "date", "valeur_objectif", "valeur_tendance") %>% dplyr::mutate(y = .data$valeur_objectif+0.5*(.data$valeur_tendance-.data$valeur_objectif), position = .data$y, label = glue::glue("**{Zone}** : diff --git a/R/creer_tableau_1_6.R b/R/creer_tableau_1_6.R index 7fed2aa474a3ee0c01c360b009b4ce0c7a7778f2..027551fd58b466916b34e4ad91c90c37fbd600c8 100644 --- a/R/creer_tableau_1_6.R +++ b/R/creer_tableau_1_6.R @@ -63,11 +63,11 @@ creer_tableau_1_6 <- function(millesime_ocsge = NULL, millesime_population = NUL TRUE ~ "") ) %>% dplyr::rename ("population_n"="population_municipale") %>% - dplyr::select (-.data$date) + dplyr::select(-"date") # table des seuils seuil_population <- population %>% - dplyr::select (.data$CodeZone,.data$seuil_pop) + dplyr::select("CodeZone", "seuil_pop") # preparation des donnees @@ -80,8 +80,8 @@ creer_tableau_1_6 <- function(millesime_ocsge = NULL, millesime_population = NUL dplyr::mutate(date=lubridate::year(lubridate::as_date(.data$date)), espace_naturel= .data$autre_surface_naturelle + .data$surface_en_eau + .data$surface_naturelle_boisee) %>% COGiter::filtrer_cog(reg = code_reg) %>% - dplyr::select (.data$TypeZone,.data$Zone,.data$CodeZone, - .data$espace_naturel,.data$espace_agricole,.data$espace_artificialise) %>% + dplyr::select ("TypeZone", "Zone", "CodeZone", + "espace_naturel", "espace_agricole", "espace_artificialise") %>% dplyr::filter(.data$TypeZone == "Communes") ocsge3 <- ocsge2 %>% @@ -104,14 +104,14 @@ creer_tableau_1_6 <- function(millesime_ocsge = NULL, millesime_population = NUL # donnees du tableau data2 <- data1 %>% - dplyr::select (.data$seuil_pop,.data$dep,.data$variable,.data$taux) %>% + dplyr::select("seuil_pop", "dep", "variable", "taux") %>% tidyr::pivot_wider(names_from = "variable", values_from = "taux", values_fill = 0) %>% dplyr::left_join(COGiter::departements %>% - dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), + dplyr::filter(.data$REG == code_reg) %>% + dplyr::select("DEP", "NOM_DEP"), by=c("dep"= "DEP")) %>% dplyr::rename("Departement" = "NOM_DEP") %>% - dplyr::select (.data$seuil_pop, .data$Departement, .data$espace_artificialise, .data$espace_agricole, .data$espace_naturel) + dplyr::select("seuil_pop", "Departement", "espace_artificialise", "espace_agricole", "espace_naturel") data <- data2 %>% dplyr::group_by(.data$seuil_pop) %>% @@ -125,12 +125,7 @@ creer_tableau_1_6 <- function(millesime_ocsge = NULL, millesime_population = NUL dplyr::arrange(.data$seuil_pop) %>% dplyr::mutate(seuil_pop = as.character(.data$seuil_pop)) %>% dplyr::mutate(seuil_pop = ifelse(.data$n == 1, .data$seuil_pop, "")) %>% - dplyr::select(.data$seuil_pop, - .data$Departement, - .data$espace_artificialise, - .data$espace_agricole, - .data$espace_naturel, - .data$nmax) + dplyr::select("seuil_pop", "Departement", "espace_artificialise", "espace_agricole", "espace_naturel", "nmax") # Render a bar chart with a label on the left @@ -141,7 +136,7 @@ creer_tableau_1_6 <- function(millesime_ocsge = NULL, millesime_population = NUL } tableau_1_6 <- reactable::reactable( - data %>% dplyr::select(-.data$nmax), + data %>% dplyr::select(-"nmax"), defaultPageSize = 100, sortable = FALSE, rowStyle = function(index) { diff --git a/R/creer_tableau_6_1.R b/R/creer_tableau_6_1.R index 9b54a69a3848b99fa78451196083bb8ec4708ae3..1413b5cf874a8c770f4f7cc019b369e40c696edc 100644 --- a/R/creer_tableau_6_1.R +++ b/R/creer_tableau_6_1.R @@ -33,6 +33,10 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population millesime_debut <- 2016 millesime_population_debut <- millesime_population - (millesime_stock_artif - millesime_debut) + dep_reg <- COGiter::departements %>% + dplyr::filter (.data$REG == code_reg) %>% + dplyr::select("DEP", "NOM_DEP") + if (is.numeric(code_reg)) { code_reg = as.character(code_reg) } @@ -68,11 +72,11 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population TRUE ~ "") ) %>% dplyr::rename ("population_n"="population_municipale") %>% - dplyr::select (-.data$date) + dplyr::select(-"date") # table des seuils seuil_population <- population %>% - dplyr::select (.data$CodeZone, .data$seuil_pop) + dplyr::select("CodeZone", "seuil_pop") # preparation des donnees evolution_artificialisation @@ -92,15 +96,11 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::filter (.data$date == millesime_stock_artif) %>% dplyr::group_by(.data$dep, .data$seuil_pop, .data$date) %>% dplyr::summarise(surface_artificialisee = sum(.data$surface_artificialisee, na.rm = T), - surf_cadastree = sum(.data$surf_cadastree, na.rm = T) - ) %>% + surf_cadastree = sum(.data$surf_cadastree, na.rm = T)) %>% dplyr::ungroup() %>% - dplyr::left_join(COGiter::departements %>% - dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), - by=c("dep"= "DEP")) %>% + dplyr::left_join(dep_reg, by = c("dep"= "DEP")) %>% dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::select(-"dep") evol_artif1_2 <- evol_artif1 %>% dplyr::group_by(.data$seuil_pop, .data$date) %>% @@ -110,11 +110,11 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::ungroup() %>% dplyr::mutate(Zone = COGiter::regions %>% dplyr::filter (.data$REG == code_reg) %>% - dplyr::pull(.data$NOM_REG)) + dplyr::pull("NOM_REG")) - evol_artif1 <-dplyr::bind_rows(evol_artif1,evol_artif1_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$date, .data$surface_artificialisee, .data$surf_cadastree) %>% + evol_artif1 <- dplyr::bind_rows(evol_artif1, evol_artif1_2) %>% + dplyr::select("seuil_pop", "Zone", "date", "surface_artificialisee", "surf_cadastree") %>% dplyr::mutate (part_artificialisee_du_territoire_cadastre = paste0( round((.data$surface_artificialisee / .data$surf_cadastree)*100 , 1), " %")) evol_artif2 <- evol_artif %>% @@ -124,12 +124,9 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::group_by(.data$dep, .data$seuil_pop, .data$date) %>% dplyr::summarise(surface_artificialisee_ancienne = sum(.data$surface_artificialisee, na.rm = T)) %>% dplyr::ungroup() %>% - dplyr::left_join(COGiter::departements %>% - dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), - by=c("dep"= "DEP")) %>% + dplyr::left_join(dep_reg, by=c("dep"= "DEP")) %>% dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::select(-"dep") evol_artif2_2 <- evol_artif2 %>% dplyr::group_by(.data$seuil_pop, .data$date) %>% @@ -139,8 +136,8 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::filter (.data$REG == code_reg) %>% dplyr::pull(.data$NOM_REG)) - evol_artif2 <-dplyr::bind_rows(evol_artif2,evol_artif2_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$surface_artificialisee_ancienne) + evol_artif2 <- dplyr::bind_rows(evol_artif2,evol_artif2_2) %>% + dplyr::select("seuil_pop", "Zone", "surface_artificialisee_ancienne") # preparation des donnees evol_population @@ -158,12 +155,9 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::group_by(.data$dep, .data$seuil_pop, .data$date) %>% dplyr::summarise(population_municipale = sum(.data$population_municipale, na.rm = T)) %>% dplyr::ungroup() %>% - dplyr::left_join(COGiter::departements %>% - dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), - by=c("dep"= "DEP")) %>% + dplyr::left_join(dep_reg, by = c("dep" = "DEP")) %>% dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::select(-"dep") evol_popul1_2 <- evol_popul1 %>% dplyr::group_by(.data$seuil_pop, .data$date) %>% @@ -171,10 +165,10 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::ungroup() %>% dplyr::mutate(Zone = COGiter::regions %>% dplyr::filter (.data$REG == code_reg) %>% - dplyr::pull(.data$NOM_REG)) + dplyr::pull("NOM_REG")) evol_popul1 <-dplyr::bind_rows(evol_popul1, evol_popul1_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$population_municipale) + dplyr::select("seuil_pop", "Zone", "population_municipale") evol_popul2 <- evol_popul %>% @@ -184,12 +178,9 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::group_by(.data$dep, .data$seuil_pop, .data$date) %>% dplyr::summarise(population_municipale_ancienne = sum(.data$population_municipale, na.rm = T)) %>% dplyr::ungroup() %>% - dplyr::left_join(COGiter::departements %>% - dplyr::filter (.data$REG == code_reg) %>% - dplyr::select(.data$DEP, .data$NOM_DEP), - by=c("dep"= "DEP")) %>% + dplyr::left_join(dep_reg, by=c("dep"= "DEP")) %>% dplyr::rename("Zone" = "NOM_DEP") %>% - dplyr::select(-.data$dep) + dplyr::select(-"dep") evol_popul2_2 <- evol_popul2 %>% dplyr::group_by(.data$seuil_pop, .data$date) %>% @@ -197,10 +188,10 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population dplyr::ungroup() %>% dplyr::mutate(Zone = COGiter::regions %>% dplyr::filter (.data$REG == code_reg) %>% - dplyr::pull(.data$NOM_REG)) + dplyr::pull("NOM_REG")) - evol_popul2 <-dplyr::bind_rows(evol_popul2, evol_popul2_2) %>% - dplyr::select(.data$seuil_pop, .data$Zone, .data$population_municipale_ancienne) + evol_popul2 <- dplyr::bind_rows(evol_popul2, evol_popul2_2) %>% + dplyr::select("seuil_pop", "Zone", "population_municipale_ancienne") # regroupement des donnees @@ -222,18 +213,18 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population glue::glue("communes entre\n",pop_2," et ",pop_3, " habitants"), glue::glue("communes de plus\nde ",pop_3," habitants")))) %>% dplyr::arrange(.data$seuil_pop) %>% - dplyr::select (.data$seuil_pop, - .data$Zone, - .data$surf_cadastree, - .data$surface_artificialisee, - .data$population_municipale, - .data$evolution_surf_artificialisee, - .data$part_artificialisee_du_territoire_cadastre, - .data$tc_surfaces_artificialisees, - .data$tc_population, - .data$nb_annees_pour_doubler, - .data$surf_artif_par_hab_an_x, - .data$surf_artif_par_nouv_hab_entre_x_y) + dplyr::select("seuil_pop", + "Zone", + "surf_cadastree", + "surface_artificialisee", + "population_municipale", + "evolution_surf_artificialisee", + "part_artificialisee_du_territoire_cadastre", + "tc_surfaces_artificialisees", + "tc_population", + "nb_annees_pour_doubler", + "surf_artif_par_hab_an_x", + "surf_artif_par_nouv_hab_entre_x_y") # separation des tableaux @@ -257,7 +248,7 @@ creer_tableau_6_1 <- function(millesime_stock_artif = NULL, millesime_population tableau_6_1 <- data_regroupe %>% - dplyr::select(-.data$seuil_pop) %>% + dplyr::select(-"seuil_pop") %>% knitr::kable("html", caption = "Tableau de synth\u00e8se", digits= c(0,0,0,0,0,1,1,1,0,1,1), align = "c", diff --git a/R/globals.R b/R/globals.R index 606a3cce221e81f17791b2ffc5099cd823b048bc..2ec21ca4bfc83e1463cdd4c2ae70d1b4de798370 100644 --- a/R/globals.R +++ b/R/globals.R @@ -1,5 +1,5 @@ -utils::globalVariables( +globalVariables( c("teruti","observatoire_artificialisation",".data","variable",".", - "valeur","etalement_urbain","observatoire_artificialisation_gk3", + "valeur", "valeur_ind", "etalement_urbain","observatoire_artificialisation_gk3", "stock_artificialise","population_legale","ocsge","regions") ) diff --git a/data-raw/data_tableurs.R b/data-raw/data_tableurs.R index 55675d4d63a3dcfcde95a5f69674bc2f006e78d3..3c788aa9b07a95dbb2d26bab77c1d34f9ef9ba5f 100644 --- a/data-raw/data_tableurs.R +++ b/data-raw/data_tableurs.R @@ -15,7 +15,7 @@ millesime_ocsge <- millesimes %>% dplyr::filter (donnee == "ocsge") %>% pull () millesime_obs_artif <- millesimes %>% dplyr::filter (donnee == "observatoire_artificialisation") %>% pull () millesime_population <- millesimes %>% dplyr::filter (donnee == "population_legale") %>% pull () millesime_stock_artif <- millesimes %>% dplyr::filter (donnee == "stock_artificialise") %>% pull () -millesime_debut <- 2016 #millesime debut stock artificialisation (fixe) +millesime_debut <- 2016 # millesime debut stock artificialisation (fixe) # carte 1_3 (source OCSGE) --------------- diff --git a/man/creer_carte_1_3.Rd b/man/creer_carte_1_3.Rd index 29a1d0beac122d093907fc49c8359edeb7adc996..0d763ee9260becfb6bc28bbc8ca4332a66d01d30 100644 --- a/man/creer_carte_1_3.Rd +++ b/man/creer_carte_1_3.Rd @@ -18,5 +18,5 @@ Une carte Carte communale regionale de l'artificialisation en volume selon OCSGE } \examples{ -creer_carte_1_3(millesime_ocsge=2016, code_reg = '52') +creer_carte_1_3(millesime_ocsge = 2016, code_reg = '52') } diff --git a/propre.artificialisation.Rproj b/propre.artificialisation.Rproj index 4adc5c8d1d1009ce845fc96061fbb03ab53f5c0c..69fafd4b6dddad27500cfc67efb9fb16e86a96bd 100644 --- a/propre.artificialisation.Rproj +++ b/propre.artificialisation.Rproj @@ -19,7 +19,4 @@ 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