Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • dreal-pdl/csd/propre.artificialisation
1 result
Show changes
Commits on Source (10)
Showing with 119 additions and 120 deletions
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:
......
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
......@@ -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",
......
......@@ -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,
......
......@@ -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))
......
......@@ -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",
......
......@@ -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",
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)+
......
......@@ -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()
......
......@@ -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 %>%
......
......@@ -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
......
......@@ -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))) %>%
......
......@@ -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)
......
......@@ -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) %>%
......
......@@ -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"),
......
......@@ -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")) %>%
......
......@@ -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",
......
......@@ -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",
......