Skip to content
Snippets Groups Projects

Resolve "Araignée de l'étalement urbain par département 2009/19"

17 files
+ 336
51
Compare changes
  • Side-by-side
  • Inline
Files
17
+ 97
0
#' Création du graphique lollipop de l'étalement urbain pour la région et le départements sur 10 ans.
#' @description Graphique lollipop de l'étalement urbain pour la région et les départements sur 10 ans.
#'
#' @param millesime_obs_artif_gk3 une année parmi les millésimes sélectionnables par l'utilisateur, au format numerique.
#' @param millesime_population une année parmi les millésimes sélectionnables par l'utilisateur, au format numerique.
#' @param code_reg code insee de la région sur laquelle construire le graphique
#' @param police police des titres et sous titre
#'
#' @return Un graphique lollipop
#'
#' @importFrom dplyr mutate filter select arrange group_by ungroup full_join lag
#' @importFrom forcats fct_drop fct_inorder
#' @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_markdown
#' @importFrom glue glue
#' @importFrom lubridate year
#' @importFrom mapfactory format_fr_pct
#' @importFrom scales label_number
#' @importFrom tidyr pivot_longer
#' @export
#'
#' @examples
#' creer_graphe_3_1(millesime_obs_artif_gk3 = 2019, millesime_population = 2018, code_reg = '52')
creer_graphe_3_1 <- function(millesime_obs_artif_gk3 = NULL, millesime_population = NULL, code_reg = NULL, police = "sans") {
millesime_debut <- millesime_obs_artif_gk3 - 9
if (is.numeric(code_reg)) {
code_reg = as.character(code_reg)
}
# Creation de la table utile a la production du graphique
evol_artif <- observatoire_artificialisation_gk3 %>%
dplyr::mutate(date = lubridate::year(.data$date)) %>%
COGiter::filtrer_cog(reg = code_reg) %>%
dplyr::filter(.data$TypeZone %in% c("France","R\u00e9gions", "D\u00e9partements"),
.data$date == millesime_obs_artif_gk3 | .data$date == millesime_obs_artif_gk3 - 9) %>%
dplyr::select(-.data$surface_naf) %>%
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_obs_artif_gk3) %>%
dplyr::select(.data$TypeZone, .data$CodeZone, .data$Zone, .data$evolution_artificialisation)
evol_popul <- population_legale %>%
dplyr::mutate(date = lubridate::year(.data$date)) %>%
COGiter::filtrer_cog(reg = code_reg) %>%
dplyr::filter(.data$TypeZone %in% c("R\u00e9gions", "D\u00e9partements"),
.data$date == millesime_population | .data$date == millesime_population - 9) %>%
dplyr::arrange(.data$TypeZone, .data$Zone, .data$CodeZone, .data$date) %>%
dplyr::group_by(.data$TypeZone, .data$Zone, .data$CodeZone) %>%
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)
data <- dplyr::full_join(evol_artif, evol_popul) %>%
tidyr::pivot_longer(cols = .data$evolution_artificialisation:.data$evolution_population, names_to = "indicateur", values_to = "valeur")
gg <- data %>%
dplyr::arrange(.data$TypeZone, desc(.data$Zone)) %>%
dplyr::mutate(Zone = forcats::fct_drop(.data$Zone) %>%
forcats::fct_inorder()) %>%
ggplot2::ggplot() +
ggplot2::aes(x = .data$Zone, y = .data$valeur, group = .data$indicateur, color = .data$indicateur) +
ggplot2::geom_point(size = 2, position = ggplot2::position_dodge(width = 0.5)) +
ggplot2::aes(x = .data$Zone, ymin = 0, ymax = .data$valeur, group = .data$indicateur, color = .data$indicateur) +
ggplot2::geom_linerange(size = 1.2, position = ggplot2::position_dodge(width = 0.5)) +
ggplot2::aes(label = mapfactory::format_fr_pct(.data$valeur, 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(data$valeur) * 1.1, by = 2.5),
minor_breaks = NULL,
limits = c(0, max(data$valeur) * 1.1),
labels = scales::label_number(big.mark = " ", decimal.mark = ",", suffix = " %"),
expand = c(0,0)
) +
ggplot2::labs(
title = "Taux de croissance compar\u00e9s des <span style = 'color:#FF9940'>surfaces artificialis\u00e9es</span> et de la <span style = 'color:#5770BE'>population municipale</span>",
subtitle = glue::glue("Entre {millesime_debut} et {millesime_obs_artif_gk3}, en %"),
caption = glue::glue("Source : Observatoire artificialisation {millesime_obs_artif_gk3} / Insee, calculs DREAL
Surfaces artificialis\u00e9es hors routes"),
x = NULL, y = NULL
) +
ggplot2::theme(
panel.grid.major.y = ggplot2::element_blank(),
legend.position = "none",
plot.title = ggtext::element_markdown(size = 14, lineheight = 1.8, hjust = 0, family = police),
plot.subtitle = ggplot2::element_text(size = 12, family = police),
plot.caption = ggplot2::element_text(size = 10, family = police),
) +
ggplot2::scale_color_manual(values = c("#FF9940", "#5770BE"))
return(gg)
}
Loading