diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e7311ac86e1c3bb8caaa7c3f5f2e438f7d28b63c..ed13e67612e13bfd2adb67a09c98f44701adb881 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" diff --git a/DESCRIPTION b/DESCRIPTION index d2a5ec0cdba13d82e3f8c30dc9ade55a94fee370..4c279225f97ac977f708db6efcebceeade1061c8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,8 +36,7 @@ Imports: stringr, tibble, tidyr, - tricky, - utils + tricky Suggests: rmarkdown, testthat (>= 3.0.0) @@ -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_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/globals.R b/R/globals.R index 606a3cce221e81f17791b2ffc5099cd823b048bc..082abd87d85b5785e15b41a30db2248e152fcf60 100644 --- a/R/globals.R +++ b/R/globals.R @@ -1,4 +1,4 @@ -utils::globalVariables( +globalVariables( c("teruti","observatoire_artificialisation",".data","variable",".", "valeur","etalement_urbain","observatoire_artificialisation_gk3", "stock_artificialise","population_legale","ocsge","regions") 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