From bf2180bd590d0140af05ec3814135183779d5592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Theuli=C3=A8re?= <mael.theuliere@developpement-durable.gouv.fr> Date: Mon, 17 Jan 2022 09:19:13 +0000 Subject: [PATCH] Poursuite template --- .Rbuildignore | 2 + DESCRIPTION | 8 +- NAMESPACE | 19 +- R/FormatDate.R | 39 +-- R/creer_chiffres_clefs.R | 105 ++++++ R/creer_graphique_evolution_annuelle.R | 102 ++++-- ...rim.R => creer_graphique_evolution_trim.R} | 8 +- ... creer_graphique_investissement_locatif.R} | 27 +- R/creer_graphique_series_temporelles.R | 58 ++++ R/creer_graphique_series_temporelles_prix.R | 86 +++++ R/creer_tableau_synthese_annuelle.R | 71 ++++ R/creer_tableau_synthese_trimestrielle.R | 67 ++++ R/data_prep.R | 15 +- R/globals.R | 2 +- R/graphique_series_temporelles.R | 45 --- R/graphique_series_temporelles_prix.R | 64 ---- R/graphique_synthese.R | 72 ++++ R/label_rang.R | 6 +- R/set_theme.R | 21 ++ R/tableau_synthese_annuelle.R | 62 ---- R/tableau_synthese_trimestrielle.R | 56 ---- README.md | 4 +- data-raw/data-raw-ecln-sas-R.R | 59 ++-- .../ecln_conjoncture/skeleton/.gitignore | 2 + .../ecln_conjoncture/skeleton/footer.html | 37 ++ .../ecln_conjoncture/skeleton/header.html | 9 + .../ecln_conjoncture/skeleton/skeleton.Rmd | 316 ++++++++++++++++++ .../templates/ecln_conjoncture/template.yaml | 4 + man/creer_chiffres_clefs_ecln.Rd | 28 ++ man/creer_graphique_evolution_annuelle.Rd | 10 +- ...m.Rd => creer_graphique_evolution_trim.Rd} | 8 +- ...creer_graphique_investissement_locatif.Rd} | 12 +- ... => creer_graphique_series_temporelles.Rd} | 11 +- ...reer_graphique_series_temporelles_prix.Rd} | 12 +- ...el.Rd => creer_tableau_synthese_annuel.Rd} | 8 +- ...> creer_tableau_synthese_trimestrielle.Rd} | 11 +- man/en_trimestre.Rd | 17 + man/format_fr_nb.Rd | 23 ++ man/format_fr_pct.Rd | 21 ++ man/indic_ecln.Rd | 2 +- man/set_theme.Rd | 17 + 41 files changed, 1166 insertions(+), 380 deletions(-) create mode 100644 R/creer_chiffres_clefs.R rename R/{graphique_evolution_trim.R => creer_graphique_evolution_trim.R} (92%) rename R/{graphique_investissement_locatif.R => creer_graphique_investissement_locatif.R} (66%) create mode 100644 R/creer_graphique_series_temporelles.R create mode 100644 R/creer_graphique_series_temporelles_prix.R create mode 100644 R/creer_tableau_synthese_annuelle.R create mode 100644 R/creer_tableau_synthese_trimestrielle.R delete mode 100644 R/graphique_series_temporelles.R delete mode 100644 R/graphique_series_temporelles_prix.R create mode 100644 R/graphique_synthese.R create mode 100644 R/set_theme.R delete mode 100644 R/tableau_synthese_annuelle.R delete mode 100644 R/tableau_synthese_trimestrielle.R create mode 100644 inst/rmarkdown/templates/ecln_conjoncture/skeleton/.gitignore create mode 100644 inst/rmarkdown/templates/ecln_conjoncture/skeleton/footer.html create mode 100644 inst/rmarkdown/templates/ecln_conjoncture/skeleton/header.html create mode 100644 inst/rmarkdown/templates/ecln_conjoncture/skeleton/skeleton.Rmd create mode 100644 inst/rmarkdown/templates/ecln_conjoncture/template.yaml create mode 100644 man/creer_chiffres_clefs_ecln.Rd rename man/{graphique_evolution_trim.Rd => creer_graphique_evolution_trim.Rd} (78%) rename man/{graphique_investissement_locatif.Rd => creer_graphique_investissement_locatif.Rd} (73%) rename man/{graphique_series_temporelles.Rd => creer_graphique_series_temporelles.Rd} (73%) rename man/{graphique_series_temporelles_prix.Rd => creer_graphique_series_temporelles_prix.Rd} (71%) rename man/{tableau_synthese_annuel.Rd => creer_tableau_synthese_annuel.Rd} (73%) rename man/{tableau_synthese_trimestrielle.Rd => creer_tableau_synthese_trimestrielle.Rd} (53%) create mode 100644 man/en_trimestre.Rd create mode 100644 man/format_fr_nb.Rd create mode 100644 man/format_fr_pct.Rd create mode 100644 man/set_theme.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 0f63be5..db3ac46 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,3 +4,5 @@ ^data-raw$ ^extdata$ ^LICENSE\.md$ +inst/rmarkdown/templates/ecln_conjoncture/skeleton/www/* +inst/rmarkdown/templates/ecln_conjoncture/skeleton/skeleton.html diff --git a/DESCRIPTION b/DESCRIPTION index 01bcea3..4811904 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,13 +12,14 @@ License: GPL (>= 3) Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 Imports: COGiter, dplyr, lubridate, stringr, forcats, + geofacet, ggforce, ggplot2, glue, @@ -28,8 +29,11 @@ Imports: rlang, kableExtra, knitr, - tidyr + tidyr, + attempt, + drealdown Remotes: + gitlab::dreal-datalab/drealdown, MaelTheuliere/COGiter Depends: R (>= 2.10) diff --git a/NAMESPACE b/NAMESPACE index 530ca2f..3302324 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,15 +3,18 @@ export("%>%") export(FormatCaractere) export(FormatDate) +export(creer_chiffres_clefs_ecln) export(creer_graphique_evolution_annuelle) +export(creer_graphique_evolution_trim) +export(creer_graphique_investissement_locatif) +export(creer_graphique_series_temporelles) +export(creer_graphique_series_temporelles_prix) +export(creer_tableau_synthese_annuel) +export(creer_tableau_synthese_trimestrielle) export(data_prep) -export(graphique_evolution_trim) -export(graphique_investissement_locatif) -export(graphique_series_temporelles) -export(graphique_series_temporelles_prix) -export(tableau_synthese_annuel) -export(tableau_synthese_trimestrielle) +export(set_theme) importFrom(COGiter,filtrer_cog) +importFrom(attempt,stop_if_not) importFrom(dplyr,arrange) importFrom(dplyr,bind_rows) importFrom(dplyr,case_when) @@ -21,10 +24,12 @@ importFrom(dplyr,full_join) importFrom(dplyr,mutate) importFrom(dplyr,pull) importFrom(dplyr,select) +importFrom(drealdown,my_icon) importFrom(forcats,fct_drop) importFrom(forcats,fct_inorder) importFrom(forcats,fct_recode) importFrom(forcats,fct_relevel) +importFrom(geofacet,facet_geo) importFrom(ggforce,geom_mark_circle) importFrom(ggplot2,aes) importFrom(ggplot2,coord_flip) @@ -42,10 +47,12 @@ importFrom(ggplot2,position_dodge) importFrom(ggplot2,scale_x_date) importFrom(ggplot2,scale_y_continuous) importFrom(ggplot2,theme) +importFrom(ggplot2,theme_set) importFrom(glue,glue) importFrom(gouvdown,gouv_colors) importFrom(gouvdown,scale_color_gouv_discrete) importFrom(gouvdown,scale_fill_gouv_discrete) +importFrom(gouvdown,theme_gouv) importFrom(grid,unit) importFrom(kableExtra,add_header_above) importFrom(kableExtra,add_indent) diff --git a/R/FormatDate.R b/R/FormatDate.R index af56509..3a440aa 100644 --- a/R/FormatDate.R +++ b/R/FormatDate.R @@ -12,28 +12,26 @@ #' #' @examples #' FormatDate("2010-10", Periodicite = "Mois") - #' @importFrom dplyr case_when #' @importFrom lubridate ymd days #' @importFrom stringr str_split_fixed str_c str_replace -FormatDate<-function(Periode,Periodicite,sep="-") { - - Periode1=stringr::str_split_fixed(Periode,sep,2)[,1] - Periode2=stringr::str_split_fixed(Periode,sep,2)[,2] +FormatDate <- function(Periode, Periodicite, sep = "-") { + Periode1 <- stringr::str_split_fixed(Periode, sep, 2)[, 1] + Periode2 <- stringr::str_split_fixed(Periode, sep, 2)[, 2] - if (Periodicite=="Trim") { + if (Periodicite == "Trim") { return( lubridate::ymd(dplyr::case_when( - Periode2 %in% c("Q1","T1","1") ~ stringr::str_c(Periode1,"0331"), - Periode2 %in% c("Q2","T2","2") ~ stringr::str_c(Periode1,"0630"), - Periode2 %in% c("Q3","T3","3") ~ stringr::str_c(Periode1,"0930"), - Periode2 %in% c("Q4","T4","4") ~ stringr::str_c(Periode1,"1231") - ) + Periode2 %in% c("Q1", "T1", "1") ~ stringr::str_c(Periode1, "0331"), + Periode2 %in% c("Q2", "T2", "2") ~ stringr::str_c(Periode1, "0630"), + Periode2 %in% c("Q3", "T3", "3") ~ stringr::str_c(Periode1, "0930"), + Periode2 %in% c("Q4", "T4", "4") ~ stringr::str_c(Periode1, "1231") )) + ) } - if (Periodicite=="Mois") { + if (Periodicite == "Mois") { return( - lubridate::ymd(stringr::str_c(stringr::str_replace(Periode,sep,""),"01")) %m+% months(1) %m+% lubridate::days(-1) + lubridate::ymd(stringr::str_c(stringr::str_replace(Periode, sep, ""), "01")) %m+% months(1) %m+% lubridate::days(-1) ) } } @@ -50,15 +48,14 @@ FormatDate<-function(Periode,Periodicite,sep="-") { #' #' @examples #' FormatCaractere("2010-10-01") -FormatCaractere<-function(Periode) { - trim<- dplyr::case_when( - lubridate::month(Periode) <=3 ~ "T1", - lubridate::month(Periode) <=6 ~ "T2", - lubridate::month(Periode) <=9 ~ "T3", - lubridate::month(Periode) <=12 ~ "T4" +FormatCaractere <- function(Periode) { + trim <- dplyr::case_when( + lubridate::month(Periode) <= 3 ~ "T1", + lubridate::month(Periode) <= 6 ~ "T2", + lubridate::month(Periode) <= 9 ~ "T3", + lubridate::month(Periode) <= 12 ~ "T4" ) return( - paste0(lubridate::year(Periode),trim) + paste0(lubridate::year(Periode), trim) ) } - diff --git a/R/creer_chiffres_clefs.R b/R/creer_chiffres_clefs.R new file mode 100644 index 0000000..83923d5 --- /dev/null +++ b/R/creer_chiffres_clefs.R @@ -0,0 +1,105 @@ +#' Converti une date en trimestre +#' +#' @param date une date +#' +#' @return une chaine de caractère +#' @importFrom dplyr case_when +#' @importFrom lubridate month year +en_trimestre <- function(date) { + trim <- dplyr::case_when( + lubridate::month(date) <= 3 ~ "1er", + lubridate::month(date) <= 6 ~ "2\u00e8me", + lubridate::month(date) <= 9 ~ "3\u00e8me", + lubridate::month(date) <= 12 ~ "4\u00e8me" + ) + return( + paste(trim, "trimestre", lubridate::year(date)) + ) +} + +#' Fonction utilitaire de formatage en pourcentage pour le francais +#' +#' @description fonction utilitaire de formatage en pourcentage pour le francais + +#' @param x un nombre à formater en pourcentage +#' @param dec un entier désignant le nombre de chiffres après la virgule souhaité (1 par défaut) +#' @param sign TRUE pour avoir le signe +/- +#' +#' @return une chaîne de texte, x %, avec transformation de la décimale en virgule et insertion d'un espace insécable +#' +#' @importFrom attempt stop_if_not +format_fr_pct <- function(x, dec = 1, sign = TRUE) { + attempt::stop_if_not(x, is.numeric, msg = "x n'est pas un nombre, revoyez la saisie de l'argument de format_fr_pct(x, dec)") + if (sign == FALSE) { + res <- paste0(formatC(abs(x), decimal.mark = ",", big.mark = "\u202f", format = "f", digits = dec), "\u00a0%") + } + if (sign == TRUE) { + res <- paste0(formatC(x, decimal.mark = ",", big.mark = "\u202f", format = "f", digits = dec), "\u00a0%") + if (x > 0) { + res <- paste0("+", res) + } + } + return(res) +} + +#' Fonction utilitaire de formatage de nombre pour le francais +#' +#' @description fonction utilitaire de formatage de nombre pour le francais + +#' @param x un nombre à formater en français +#' @param dec un entier désignant le nombre de chiffres après la virgule souhaité (1 par défaut) +#' @param big_mark le séparateur des milliers +#' @param sign TRUE pour avoir le signe +/- +#' @return une chaîne de texte avec transformation de la décimale en virgule et insertion d'un caractère spécifié via big_mark au niveau du séparateur de milliers +#' @importFrom attempt stop_if_not +format_fr_nb <- function(x, dec = 1, big_mark, sign = FALSE) { + attempt::stop_if_not(x, is.numeric, msg = "x n'est pas un nombre, revoyez la saisie de l'argument de format_fr_pct(x, dec)") + if (missing("big_mark")) { + big_mark <- "\u202f" + } + if (sign == FALSE) { + x <- abs(x) + } + res <- paste0(formatC(x, decimal.mark = ",", format = "f", digits = dec, big.mark = big_mark)) + if (sign == TRUE & x > 0) { + res <- paste0("+", res) + } + return(res) +} + + + +#' Chiffres clefs pour la publication +#' +#' @param data le dataframe avec les données ecln +#' @param indicateur Ventes, Mises en vente ou encours +#' @param type_logement Appartements ou Maisons +#' @param type_indicateur cumul annuel ou valeur trimestrielle +#' +#' @return du code html +#' @export +#' @importFrom dplyr filter +#' @importFrom glue glue +#' @importFrom drealdown my_icon +creer_chiffres_clefs_ecln <- function(data = indic_ecln, + type_logement = "Logements", + indicateur = "Ventes", + type_indicateur = "Trimestriel") { + indic <- paste0(indicateur, " - ", type_logement) + + df <- data %>% + dplyr::filter( + Indicateur == indic, + TypeIndicateur == type_indicateur, + TypeZone == "R\u00e9gions", + Periode == max(Periode) + ) + val <- list( + periode = en_trimestre(df$Periode), + valeur = format_fr_nb(df$Valeur, dec = 0), + evolution = format_fr_pct(df$TauxEvolution12Mois, dec = 1) + ) + res <- glue::glue("{drealdown::my_icon('la-building', size=2)} <b>{val$valeur}</b> logements neufs vendus au {val$periode}<br> + {drealdown::my_icon('la-line-chart', size=2)} <b>{val$evolution}</b> sur un an") + return(res) +} diff --git a/R/creer_graphique_evolution_annuelle.R b/R/creer_graphique_evolution_annuelle.R index 988c8ce..c4c7b39 100644 --- a/R/creer_graphique_evolution_annuelle.R +++ b/R/creer_graphique_evolution_annuelle.R @@ -5,53 +5,81 @@ #' @param type_zone Liste des types de zonage à intégrer dans la facette. #' @param titre Le titre du graphique. #' @param bas_de_page Le bas de page du graphique. +#' @param type_facet type de facette : grille pour une matrice, geo pour une +#' @param ncol_facet Le nombre de colonnes dans la facette. #' #' @return Un graphique ggplot2. #' @importFrom dplyr filter mutate arrange #' @importFrom ggplot2 ggplot aes geom_bar coord_flip geom_label facet_wrap scale_y_continuous labs position_dodge #' @importFrom scales format_format #' @importFrom lubridate %m-% +#' @importFrom geofacet facet_geo #' @export -creer_graphique_evolution_annuelle<-function(data = indic_ecln, - type_zone = c("R\u00e9gions","D\u00e9partements"), - type_logement = "collectif", - titre="", - bas_de_page=""){ - indic<-c("Encours - Appartements", - "Mises en vente - Appartements", - "Ventes - Appartements") - if (type_logement=="individuel") { - indic<- c("Encours - Maisons", - "Mises en vente - Maisons", - "Ventes - Maisons") +creer_graphique_evolution_annuelle <- function(data = indic_ecln, + type_zone = c("France", "R\u00e9gions", "D\u00e9partements"), + type_logement = "collectif", + titre = "", + bas_de_page = "", + type_facet = "classique", + ncol_facet = 4) { + indic <- c( + "Encours - Appartements", + "Mises en vente - Appartements", + "Ventes - Appartements" + ) + if (type_logement == "individuel") { + indic <- c( + "Encours - Maisons", + "Mises en vente - Maisons", + "Ventes - Maisons" + ) } df <- data %>% - dplyr::filter(.data$Indicateur %in% indic, - .data$TypeZone %in% type_zone, - .data$TypeIndicateur=="Cumul annuel", - .data$Periode==max(.data$Periode)|.data$Periode==max(.data$Periode) %m-% years(1)) %>% - dplyr::mutate(Periode=FormatCaractere(.data$Periode), - Indicateur=str_split_fixed(.data$Indicateur," - ",2)[,1]) %>% + dplyr::filter( + .data$Indicateur %in% indic, + .data$TypeZone %in% type_zone, + .data$TypeIndicateur == "Cumul annuel", + .data$Periode == max(.data$Periode) | .data$Periode == max(.data$Periode) %m-% years(1) + ) %>% + dplyr::mutate( + Periode = FormatCaractere(.data$Periode), + Indicateur = str_split_fixed(.data$Indicateur, " - ", 2)[, 1] + ) %>% dplyr::arrange(.data$Zone) - ggplot2::ggplot(data = df, ggplot2::aes(x=.data$Periode,weight=.data$Valeur,fill=.data$Indicateur)) + - ggplot2::geom_bar(position=ggplot2::position_dodge())+ - ggplot2::coord_flip()+ - ggplot2::geom_label(data=df, - ggplot2::aes(label=format(round(.data$Valeur),big.mark = " "), - x=.data$Periode, - y=.data$Valeur, - group=.data$Indicateur), - position=position_dodge(0.9), - color="white", - fill="grey", - alpha=.2, - fontface="bold", - hjust=1.2 - )+ - ggplot2::facet_wrap(~.data$Zone,scales="free",ncol=4)+ - ggplot2::scale_y_continuous(labels=scales::format_format(big.mark=" "))+ - ggplot2::labs(title=titre,subtitle="R\u00e9alis\u00e9es sur les 12 derniers mois",x="Trimestre",y="", - caption=bas_de_page,fill="") + p <- ggplot2::ggplot(data = df, ggplot2::aes(x = .data$Periode, weight = .data$Valeur, fill = .data$Indicateur)) + + ggplot2::geom_bar(position = ggplot2::position_dodge()) + + ggplot2::coord_flip() + + ggplot2::geom_label( + data = df, + ggplot2::aes( + label = format(round(.data$Valeur), big.mark = " "), + x = .data$Periode, + y = .data$Valeur, + group = .data$Indicateur + ), + position = position_dodge(0.9), + color = "white", + fill = "grey", + alpha = .2, + fontface = "bold", + hjust = 1.2 + ) + + ggplot2::scale_y_continuous(labels = scales::format_format(big.mark = " ")) + + gouvdown::scale_fill_gouv_discrete(palette = "pal_gouv_qual2") + + ggplot2::labs( + title = titre, subtitle = "R\u00e9alis\u00e9es sur les 12 derniers mois", x = "Trimestre", y = "", + caption = bas_de_page, fill = "" + ) + if (type_facet == "classique") { + p <- p + + ggplot2::facet_wrap(~ .data$Zone, scales = "free", ncol = ncol_facet) + } + + if (type_facet == "grille") { + p <- p + + geofacet::facet_geo(~Zone, grid = mygrid, scales = "free", drop = TRUE) + } + return(p) } diff --git a/R/graphique_evolution_trim.R b/R/creer_graphique_evolution_trim.R similarity index 92% rename from R/graphique_evolution_trim.R rename to R/creer_graphique_evolution_trim.R index 895b670..fcd06c4 100644 --- a/R/graphique_evolution_trim.R +++ b/R/creer_graphique_evolution_trim.R @@ -16,10 +16,10 @@ #' @importFrom grid unit #' @importFrom lubridate quarter year #' @importFrom stringr str_c -graphique_evolution_trim <- function(data = indic_ecln, - indicateur = "Ventes - Logements", - zone = "Pays de la Loire", - titre = "Ventes de logements neufs en Pays de la Loire") { +creer_graphique_evolution_trim <- function(data = indic_ecln, + indicateur = "Ventes - Logements", + zone = "Pays de la Loire", + titre = "Ventes de logements neufs en Pays de la Loire") { per <- data %>% dplyr::select(.data$Periode) %>% dplyr::distinct() %>% diff --git a/R/graphique_investissement_locatif.R b/R/creer_graphique_investissement_locatif.R similarity index 66% rename from R/graphique_investissement_locatif.R rename to R/creer_graphique_investissement_locatif.R index f82df37..556e9f6 100644 --- a/R/graphique_investissement_locatif.R +++ b/R/creer_graphique_investissement_locatif.R @@ -15,15 +15,18 @@ #' @importFrom ggplot2 ggplot aes geom_area scale_x_date scale_y_continuous labs facet_wrap #' @importFrom scales format_format #' @importFrom stringr str_split_fixed +#' @importFrom geofacet facet_geo #' #' @examples -graphique_investissement_locatif <- function(data = indic_ecln, - type_logement = "Appartements", - type_zone = c("R\u00e9gions","D\u00e9partements"), - type_indicateur = "Cumul annuel", - titre = "", - soustitre = "", - bas_de_page = "") { +creer_graphique_investissement_locatif <- function(data = indic_ecln, + type_logement = "Appartements", + type_zone = c("R\u00e9gions", "D\u00e9partements"), + type_indicateur = "Cumul annuel", + titre = "", + soustitre = "", + bas_de_page = "", + type_facet = "classique", + ncol_facet = 4) { indic <- c( "Ventes hors investissement locatif - Appartements", "Ventes en investissement locatif - Appartements" @@ -70,7 +73,15 @@ graphique_investissement_locatif <- function(data = indic_ecln, caption = bas_de_page ) if (nlevels(data_prep$Zone) > 1) { - p <- p + ggplot2::facet_wrap(~Zone, scales = "free", ncol = 4) + if (type_facet == "classique") { + p <- p + + ggplot2::facet_wrap(~ .data$Zone, scales = "free", ncol = ncol_facet) + } + + if (type_facet == "grille") { + p <- p + + geofacet::facet_geo(~Zone, grid = mygrid, scales = "free", drop = TRUE) + } } return(p) } diff --git a/R/creer_graphique_series_temporelles.R b/R/creer_graphique_series_temporelles.R new file mode 100644 index 0000000..2e43729 --- /dev/null +++ b/R/creer_graphique_series_temporelles.R @@ -0,0 +1,58 @@ +#' graphique en série temporelle à facette +#' +#' @param data Le dataframe avec les données ecln. +#' @param type_logement Appartements ou Maisons. +#' @param indicateurs Un vecteur d'indicateur à visualiser dans le graphique. +#' @param type_zone Liste des types de zonage à intégrer dans la facette. +#' @param titre Le titre du graphique. +#' @param bas_de_page Le bas de page du graphique. +#' @param ncol_facet Le nombre de colonnes dans la facette. +#' @return Un graphique ggplot2. +#' @export +#' @importFrom dplyr filter mutate +#' @importFrom ggplot2 ggplot aes geom_line facet_wrap scale_y_continuous scale_x_date labs +#' @importFrom gouvdown scale_color_gouv_discrete +#' @importFrom scales format_format +#' @importFrom geofacet facet_geo +#' @examples +creer_graphique_series_temporelles <- function(data = indic_ecln, + type_logement = "Appartements", + indicateurs = c("Encours", "Mises en vente", "Ventes"), + type_zone = c("France", "R\u00e9gions", "D\u00e9partements"), + titre = "", + bas_de_page = "", + type_facet = "classique", + ncol_facet = 4) { + indic <- paste0(indicateurs, " - ", type_logement) + p <- data %>% + dplyr::filter( + .data$Indicateur %in% indic, + .data$TypeZone %in% type_zone, + .data$TypeIndicateur == "Cumul annuel" + ) %>% + dplyr::mutate(Indicateur = str_split_fixed(.data$Indicateur, " - ", 2)[, 1]) %>% + ggplot2::ggplot() + + ggplot2::aes(x = .data$Periode, y = .data$Valeur, color = .data$Indicateur, fill = .data$Indicateur, group = .data$Indicateur) + + ggplot2::geom_line(size = 1.2) + + ggplot2::scale_y_continuous(labels = scales::format_format(big.mark = " "), limits = c(0, NA)) + + ggplot2::scale_x_date(date_labels = "%y", date_breaks = "1 year") + + gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_qual2") + + ggplot2::labs( + title = titre, + x = "", + y = "", + fill = "", + color = "", + caption = bas_de_page + ) + if (type_facet == "classique") { + p <- p + + ggplot2::facet_wrap(~ .data$Zone, scales = "free", ncol = ncol_facet) + } + + if (type_facet == "grille") { + p <- p + + geofacet::facet_geo(~Zone, grid = mygrid, scales = "free", drop = TRUE) + } + return(p) +} diff --git a/R/creer_graphique_series_temporelles_prix.R b/R/creer_graphique_series_temporelles_prix.R new file mode 100644 index 0000000..bf92b0a --- /dev/null +++ b/R/creer_graphique_series_temporelles_prix.R @@ -0,0 +1,86 @@ +#' graphique sur l'évolution du prix de vente des biens. +#' +#' @param data Le dataframe. +#' @param type_logement Appartements ou Maisons. +#' @param type_indicateur Cumul annuel ou valeur trimestrielle. +#' @param type_zone Liste des types de zonage à intégrer dans la facette. +#' @param titre Le titre du graphique. +#' @param bas_de_page Le bas de page du graphique. +#' +#' @return Un graphique ggplot2. +#' @export +#' @importFrom dplyr filter mutate +#' @importFrom forcats fct_drop +#' @importFrom ggplot2 ggplot aes geom_line geom_point theme scale_x_date scale_y_continuous labs facet_wrap +#' @importFrom scales dollar_format +#' @importFrom stringr str_split_fixed +#' @importFrom gouvdown scale_color_gouv_discrete +#' @examples +creer_graphique_series_temporelles_prix <- function(data = indic_ecln, + type_logement = "Appartements", + type_zone = c("R\u00e9gions", "D\u00e9partements"), + type_indicateur = "Cumul annuel", + titre = "", + bas_de_page = "", + type_facet = "classique", + ncol_facet = 4) { + indic <- c("PrixM2 - Appartements") + if (type_logement == "Maisons") { + indic <- c("PrixPar - Maisons") + } + + data_prep <- data %>% + dplyr::filter( + .data$Indicateur %in% indic, + .data$TypeIndicateur == type_indicateur, + .data$TypeZone %in% type_zone + ) %>% + dplyr::mutate( + Zone = forcats::fct_drop(.data$Zone), + Indicateur = stringr::str_split_fixed(.data$Indicateur, " - ", 2)[, 1] + ) + + + p <- ggplot2::ggplot( + data_prep, + ggplot2::aes( + x = .data$Periode, + y = .data$Valeur, + color = .data$Indicateur, + fill = .data$Indicateur, + group = .data$Indicateur + ) + ) + + ggplot2::geom_line(size = 1.2) + + ggplot2::geom_point(data = data %>% + dplyr::filter( + .data$Indicateur %in% indic, + .data$TypeIndicateur == type_indicateur, + .data$TypeZone %in% type_zone, + .data$Periode == max(.data$Periode) + )) + + ggplot2::theme(legend.position = "none") + + ggplot2::scale_x_date(date_labels = "%y", date_breaks = "1 year") + + ggplot2::scale_y_continuous(labels = scales::dollar_format(big.mark = " ", decimal_mark = ",", prefix = "", suffix = " \u20ac")) + + gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_qual2") + + ggplot2::labs( + title = titre, + x = "", + y = "", + fill = "", + color = "", + caption = bas_de_page + ) + if (nlevels(data_prep$Zone) > 1) { + if (type_facet == "classique") { + p <- p + + ggplot2::facet_wrap(~ .data$Zone, scales = "free", ncol = ncol_facet) + } + + if (type_facet == "grille") { + p <- p + + geofacet::facet_geo(~Zone, grid = mygrid, scales = "free", drop = TRUE) + } + } + return(p) +} diff --git a/R/creer_tableau_synthese_annuelle.R b/R/creer_tableau_synthese_annuelle.R new file mode 100644 index 0000000..e80faa3 --- /dev/null +++ b/R/creer_tableau_synthese_annuelle.R @@ -0,0 +1,71 @@ +#' tableau de synthèse des données en cumul annuel +#' +#' @param data Le dataframe. +#' @param type_logement Collectifs ou individuels. +#' @param type_zone Liste des types de zonage à intégrer dans la facette. +#' @return Un table kable +#' @importFrom dplyr filter mutate pull select full_join arrange +#' @importFrom kableExtra kable_styling row_spec add_header_above add_indent +#' @importFrom knitr kable +#' @importFrom stringr str_split_fixed +#' @importFrom tidyr spread +#' @export +creer_tableau_synthese_annuel <- function(data = indic_ecln, + type_zone = c("France", "R\u00e9gions", "D\u00e9partements"), + type_logement = "collectif") { + indic <- c( + "Encours - Appartements", + "Mises en vente - Appartements", + "Ventes - Appartements", + "PrixM2 - Appartements" + ) + if (type_logement == "individuel") { + indic <- c( + "Encours - Maisons", + "Mises en vente - Maisons", + "Ventes - Maisons", + "PrixPar - Maisons" + ) + } + input <- indic_ecln %>% + dplyr::filter( + .data$Indicateur %in% indic, + .data$TypeZone %in% type_zone, + .data$TypeIndicateur == "Cumul annuel", + .data$Periode == max(.data$Periode) + ) %>% + dplyr::mutate(Indicateur = stringr::str_split_fixed(.data$Indicateur, "-", 2)[, 1]) + + nombre_zone <- length(unique(input$CodeZone)) + nombre_fr_dep_reg <- 1 + length(unique(input %>% dplyr::filter(.data$TypeZone %in% c("France", "R\u00e9gions", "D\u00e9partements")) %>% dplyr::pull(.data$CodeZone))) + res <- input %>% + dplyr::select(.data$TypeZone, .data$Zone, .data$Indicateur, .data$Valeur) %>% + tidyr::spread(.data$Indicateur, .data$Valeur) %>% + dplyr::full_join( + input %>% + dplyr::select(.data$TypeZone, .data$Zone, .data$Indicateur, .data$TauxEvolution12Mois) %>% + tidyr::spread(.data$Indicateur, .data$TauxEvolution12Mois), + by = c("TypeZone", "Zone") + ) %>% + dplyr::arrange(.data$Zone) %>% + dplyr::select(2, 6, 10, 4, 8, 3, 7, 5, 9) %>% + knitr::kable("html", + col.names = c( + "Zone", "Sur les 12 derniers mois", "Evolution sur un an (en %)", + "Sur les 12 derniers mois", "Evolution sur un an (en %)", + "En fin de p\u00e9riode", "Evolution sur un an (en %)", + "Prix moyen sur les 12 derniers mois (en \u20ac)", "Evolution sur un an (en %)" + ), + digits = c(0, 0, 1, 0, 1, 0, 1, 0, 1), + format.args = list(big.mark = " ", decimal.mark = ",") + ) %>% + kableExtra::kable_styling(font_size = 12) %>% + kableExtra::row_spec(1:2, bold = T, background = "#f0f0f5") %>% + kableExtra::add_header_above(c(" " = 1, "Ventes" = 2, "Mises en vente" = 2, "Encours" = 2, "Prix au m2" = 2)) %>% + kableExtra::add_indent(c(3:nombre_zone)) + if ("ABC" %in% type_zone) { + res <- res %>% + kableExtra::row_spec(nombre_fr_dep_reg:nombre_zone, bold = T, background = "#bebece") + } + return(res) +} diff --git a/R/creer_tableau_synthese_trimestrielle.R b/R/creer_tableau_synthese_trimestrielle.R new file mode 100644 index 0000000..4beb9aa --- /dev/null +++ b/R/creer_tableau_synthese_trimestrielle.R @@ -0,0 +1,67 @@ +#' Création du tableau de synthèse trimestrielle +#' +#' @param data Le dataframe. +#' @param type_logement Collectifs ou individuels. +#' +#' @return un tableau kable +#' @export +#' @importFrom dplyr filter mutate select full_join arrange +#' @importFrom kableExtra kable_styling row_spec add_header_above +#' @importFrom knitr kable +#' @importFrom stringr str_split_fixed +#' @importFrom tidyr spread +creer_tableau_synthese_trimestrielle <- function(data = indic_ecln, + type_logement = "collectif") { + indic <- c( + "Encours - Appartements", + "Mises en vente - Appartements", + "Ventes - Appartements", + "PrixM2 - Appartements" + ) + if (type_logement == "individuel") { + indic <- c( + "Encours - Maisons", + "Mises en vente - Maisons", + "Ventes - Maisons", + "PrixPar - Maisons" + ) + } + indic_ecln %>% + dplyr::filter( + .data$Indicateur %in% indic, + .data$TypeZone %in% c("France", "R\u00e9gions"), + .data$TypeIndicateur != "Cumul annuel", + .data$Periode == max(.data$Periode) + ) %>% + dplyr::mutate(Indicateur = str_split_fixed(.data$Indicateur, "-", 2)[, 1]) %>% + dplyr::select(.data$TypeZone, .data$Zone, .data$Indicateur, .data$Valeur) %>% + tidyr::spread(.data$Indicateur, .data$Valeur) %>% + dplyr::full_join( + indic_ecln %>% + dplyr::filter( + .data$Indicateur %in% indic, + .data$TypeZone %in% c("France", "R\u00e9gions"), + .data$TypeIndicateur != "Cumul annuel", + .data$Periode == max(.data$Periode) + ) %>% + dplyr::mutate(Indicateur = stringr::str_split_fixed(.data$Indicateur, "-", 2)[, 1]) %>% + dplyr::select(.data$TypeZone, .data$Zone, .data$Indicateur, .data$TauxEvolution12Mois) %>% + spread(.data$Indicateur, .data$TauxEvolution12Mois), + by = c("TypeZone", "Zone") + ) %>% + dplyr::arrange(.data$Zone) %>% + dplyr::select(2, 6, 10, 4, 8, 3, 7, 5, 9) %>% + knitr::kable("html", + col.names = c( + "Zone", "Sur le dernier trimestre", "Evolution sur un an (en %)", + "Sur le dernier trimestre", "Evolution sur un an (en %)", + "En fin de p\u00e9riode", "Evolution sur un an (en %)", + "Prix moyen sur le dernier trimestre (en \u20ac)", "Evolution sur un an (en %)" + ), + digits = c(0, 0, 1, 0, 1, 0, 1, 0, 1), + format.args = list(big.mark = " ", decimal.mark = ",") + ) %>% + kableExtra::kable_styling(font_size = 12) %>% + kableExtra::row_spec(1:2, bold = T, background = "#f0f0f5") %>% + kableExtra::add_header_above(c(" " = 1, "Ventes" = 2, "Mises en vente" = 2, "Encours" = 2, "Prix au m2" = 2)) +} diff --git a/R/data_prep.R b/R/data_prep.R index 7eedd7b..3de0c08 100644 --- a/R/data_prep.R +++ b/R/data_prep.R @@ -14,9 +14,6 @@ #' @return un dataframe filtré sur la région souhaitée #' @export data_prep <- function(reg, abc = TRUE, zone_a_secretiser = "", marches_a_secretiser = "") { - - - if (abc == FALSE) { result <- indic_ecln %>% COGiter::filtrer_cog(reg = reg, garder_supra = ">") %>% @@ -27,12 +24,12 @@ data_prep <- function(reg, abc = TRUE, zone_a_secretiser = "", marches_a_secreti Zone = forcats::fct_inorder(.data$Zone), marche = stringr::str_split_fixed(.data$Indicateur, "-", n = 2)[, 2], Valeur = ifelse(.data$Zone %in% zone_a_secretiser & - .data$marche %in% marches_a_secretiser, + .data$marche %in% marches_a_secretiser, NA, .data$Valeur ), TauxEvolution12Mois = ifelse(.data$Zone %in% zone_a_secretiser & - .data$marche %in% marches_a_secretiser, + .data$marche %in% marches_a_secretiser, NA, .data$TauxEvolution12Mois ) @@ -45,20 +42,20 @@ data_prep <- function(reg, abc = TRUE, zone_a_secretiser = "", marches_a_secreti abc <- indic_ecln %>% dplyr::filter(.data$TypeZone == "ABC") - result <- dplyr::bind_rows(result, abc) - dplyr::mutate(TypeZone = forcats::fct_relevel(as.factor(.data$TypeZone), "France", "R\u00e9gions", "D\u00e9partements", "Epci", "ABC")) %>% + result <- dplyr::bind_rows(result, abc) %>% + dplyr::mutate(TypeZone = forcats::fct_relevel(as.factor(.data$TypeZone), "France", "R\u00e9gions", "D\u00e9partements", "Epci", "ABC")) %>% dplyr::arrange(.data$TypeZone, .data$Zone) %>% dplyr::mutate( Zone = forcats::fct_drop(.data$Zone), Zone = forcats::fct_inorder(.data$Zone), marche = stringr::str_split_fixed(.data$Indicateur, "-", n = 2)[, 2], Valeur = ifelse(.data$Zone %in% zone_a_secretiser & - .data$marche %in% marches_a_secretiser, + .data$marche %in% marches_a_secretiser, NA, .data$Valeur ), TauxEvolution12Mois = ifelse(.data$Zone %in% zone_a_secretiser & - .data$marche %in% marches_a_secretiser, + .data$marche %in% marches_a_secretiser, NA, .data$TauxEvolution12Mois ) diff --git a/R/globals.R b/R/globals.R index c29f011..8d57f78 100644 --- a/R/globals.R +++ b/R/globals.R @@ -1,3 +1,3 @@ utils::globalVariables( - c("liste_zone","indic_ecln","%m-%") + c("liste_zone", "indic_ecln", "%m-%") ) diff --git a/R/graphique_series_temporelles.R b/R/graphique_series_temporelles.R deleted file mode 100644 index 6b38b31..0000000 --- a/R/graphique_series_temporelles.R +++ /dev/null @@ -1,45 +0,0 @@ -#' graphique en série temporelle à facette -#' -#' @param data Le dataframe avec les données ecln. -#' @param type_logement Appartements ou Maisons. -#' @param indicateurs Un vecteur d'indicateur à visualiser dans le graphique. -#' @param type_zone Liste des types de zonage à intégrer dans la facette. -#' @param titre Le titre du graphique. -#' @param bas_de_page Le bas de page du graphique. -#' @param ncol_facet Le nombre de colonnes dans la facette. -#' @return Un graphique ggplot2. -#' @export -#' @importFrom dplyr filter mutate -#' @importFrom ggplot2 ggplot aes geom_line facet_wrap scale_y_continuous scale_x_date labs -#' @importFrom gouvdown scale_color_gouv_discrete -#' @importFrom scales format_format -#' @examples -graphique_series_temporelles<-function(data=indic_ecln, - type_logement="Appartements", - indicateurs = c("Encours","Mises en vente","Ventes"), - type_zone = c("R\u00e9gions","D\u00e9partements"), - titre="", - bas_de_page="", - ncol_facet=4 -){ - indic <- paste0(indicateurs," - ",type_logement) - gg <- data %>% - dplyr::filter(.data$Indicateur %in% indic, - .data$TypeZone %in% type_zone, - .data$TypeIndicateur=="Cumul annuel") %>% - dplyr::mutate(Indicateur=str_split_fixed(.data$Indicateur," - ",2)[,1]) %>% - ggplot2::ggplot() + - ggplot2::aes(x=.data$Periode,y=.data$Valeur,color=.data$Indicateur,fill=.data$Indicateur,group=.data$Indicateur) + - ggplot2::geom_line(size=1.2)+ - ggplot2::facet_wrap(~.data$Zone,scales="free",ncol=ncol_facet)+ - ggplot2::scale_y_continuous(labels=scales::format_format(big.mark=" "),limits=c(0,NA)) + - ggplot2::scale_x_date(date_labels="%y",date_breaks = "1 year") + - gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_qual2") + - ggplot2::labs(title=titre, - x="", - y="", - fill="", - color="", - caption=bas_de_page) - return(gg) -} diff --git a/R/graphique_series_temporelles_prix.R b/R/graphique_series_temporelles_prix.R deleted file mode 100644 index 06c857a..0000000 --- a/R/graphique_series_temporelles_prix.R +++ /dev/null @@ -1,64 +0,0 @@ -#' graphique sur l'évolution du prix de vente des biens. -#' -#' @param data Le dataframe. -#' @param type_logement Appartements ou Maisons. -#' @param type_indicateur Cumul annuel ou valeur trimestrielle. -#' @param type_zone Liste des types de zonage à intégrer dans la facette. -#' @param titre Le titre du graphique. -#' @param bas_de_page Le bas de page du graphique. -#' -#' @return Un graphique ggplot2. -#' @export -#' @importFrom dplyr filter mutate -#' @importFrom forcats fct_drop -#' @importFrom ggplot2 ggplot aes geom_line geom_point theme scale_x_date scale_y_continuous labs facet_wrap -#' @importFrom scales dollar_format -#' @importFrom stringr str_split_fixed -#' @importFrom gouvdown scale_color_gouv_discrete -#' @examples -graphique_series_temporelles_prix<-function(data=indic_ecln, - type_logement="Appartements", - type_zone = c("R\u00e9gions","D\u00e9partements"), - type_indicateur = "Cumul annuel", - titre="", - bas_de_page=""){ - indic<-c("PrixM2 - Appartements") - if (type_logement=="Maisons") { - indic<- c("PrixPar - Maisons") - } - - data_prep<-data %>% - dplyr::filter(.data$Indicateur %in% indic, - .data$TypeIndicateur == type_indicateur, - .data$TypeZone %in% type_zone) %>% - dplyr::mutate(Zone = forcats::fct_drop(.data$Zone), - Indicateur=stringr::str_split_fixed(.data$Indicateur," - ",2)[,1]) - - - p<-ggplot2::ggplot(data_prep, - ggplot2::aes(x=.data$Periode, - y=.data$Valeur, - color=.data$Indicateur, - fill=.data$Indicateur, - group=.data$Indicateur)) + - ggplot2::geom_line(size=1.2)+ - ggplot2::geom_point(data= data %>% - dplyr::filter(.data$Indicateur %in% indic, - .data$TypeIndicateur == type_indicateur, - .data$TypeZone %in% type_zone, - .data$Periode==max(.data$Periode)))+ - ggplot2::theme(legend.position = "none")+ - ggplot2::scale_x_date(date_labels="%y",date_breaks = "1 year")+ - ggplot2::scale_y_continuous(labels=scales::dollar_format(big.mark=" ",decimal_mark=",",prefix="",suffix=" \u20ac"))+ - gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_qual2") + - ggplot2::labs(title=titre, - x="", - y="", - fill="", - color="", - caption=bas_de_page) - if (nlevels(data_prep$Zone)>1){ - p<-p+ggplot2::facet_wrap(~Zone,scales="fixed",ncol=4) - } - return(p) -} diff --git a/R/graphique_synthese.R b/R/graphique_synthese.R new file mode 100644 index 0000000..eb4f654 --- /dev/null +++ b/R/graphique_synthese.R @@ -0,0 +1,72 @@ +graphique_synthese <- function(type_logement = "Appartements", + titre = "Les ventes d'appartements neufs en Pays de la Loire", + sous_titre = "Sur 12 mois glissants", + titre_legende_carte = "", + ncol_facet = 5, + bas_de_page = "") { + p1 <- carte_volume( + type_logement = type_logement, + indicateurs = "Ventes", + titre = NULL, + titre_legende = titre_legende_carte, + bas_de_page = NULL + ) + + p3 <- graphique_investissement_locatif( + data = indic_ecln %>% + filter(TypeZone == "Régions"), + type_logement = type_logement, + titre = "", + bas_de_page = NULL + ) + + guides( + colour = F, + order = 0, + fill = guide_legend( + direction = "vertical", + keyheight = unit(2, units = "mm"), + nrow = 2 + ) + ) + p4 <- graphique_series_temporelles_prix( + data = indic_ecln %>% + filter(TypeZone == "Régions"), + type_logement = type_logement + ) + + p5 <- graphique_series_temporelles( + data = indic_ecln %>% + filter(TypeZone == "Départements"), + type_logement = type_logement, + indicateurs = "Ventes", + ncol_facet = ncol_facet, + bas_de_page = bas_de_page + ) + + theme(legend.position = "none") + + p6 <- graphique_series_temporelles( + data = indic_ecln %>% + filter(TypeZone %in% c("France", "Régions")), + type_logement = type_logement + ) + + labels <- c("Investissement locatif", "Prix de vente au m2") + if (type_logement == "Maisons") { + labels <- c("Investissement locatif", "Prix de vente par maison") + } + p <- plot_grid(p3, p4, ncol = 1, labels = labels) + p <- plot_grid(p1, p, ncol = 2, rel_widths = c(2, 1)) + p <- plot_grid(p, p5, ncol = 1, rel_heights = c(2, 1), labels = c("", "Ventes par départements")) + p <- plot_grid(p6, p, ncol = 1, rel_heights = c(1, 3)) + + title <- ggdraw() + + draw_label(titre, + fontface = "bold", hjust = .5, size = 20, fontfamily = "Roboto" + ) + sub_title <- ggdraw() + + draw_label(sous_titre, + fontface = "plain", hjust = .5, size = 15, fontfamily = "Roboto" + ) + p <- plot_grid(title, sub_title, p, ncol = 1, rel_heights = c(.03, .03, 1)) + p +} diff --git a/R/label_rang.R b/R/label_rang.R index 97e4fe3..be6624e 100644 --- a/R/label_rang.R +++ b/R/label_rang.R @@ -1,12 +1,12 @@ label_rang <- function(x) { if (x == 1) { - res <- paste0(x,"er") + res <- paste0(x, "er") } if (x == 2) { - res <- paste0(x,"nd") + res <- paste0(x, "nd") } if (x > 2) { - res <- paste0(x,"\u00e8me") + res <- paste0(x, "\u00e8me") } return(res) } diff --git a/R/set_theme.R b/R/set_theme.R new file mode 100644 index 0000000..84e7dde --- /dev/null +++ b/R/set_theme.R @@ -0,0 +1,21 @@ + +#' Definir le theme par defaut des graphiques de la publication +#' +#' @return une fonction +#' @importFrom ggplot2 theme_set theme +#' @importFrom gouvdown theme_gouv +#' @export +#' @examples +#' set_theme() +set_theme <- function() { + ggplot2::theme_set(gouvdown::theme_gouv( + base_size = 12, + strip_text_size = 12, + plot_title_size = 20, + subtitle_size = 16 + ) + + ggplot2::theme( + legend.position = "bottom", + plot.caption.position = "plot" + )) +} diff --git a/R/tableau_synthese_annuelle.R b/R/tableau_synthese_annuelle.R deleted file mode 100644 index a7474d1..0000000 --- a/R/tableau_synthese_annuelle.R +++ /dev/null @@ -1,62 +0,0 @@ -#' tableau de synthèse des données en cumul annuel -#' -#' @param data Le dataframe. -#' @param type_logement Collectifs ou individuels. -#' @param type_zone Liste des types de zonage à intégrer dans la facette. -#' @return Un table kable -#' @importFrom dplyr filter mutate pull select full_join arrange -#' @importFrom kableExtra kable_styling row_spec add_header_above add_indent -#' @importFrom knitr kable -#' @importFrom stringr str_split_fixed -#' @importFrom tidyr spread -#' @export -tableau_synthese_annuel<-function(data = indic_ecln, - type_zone = c("France","R\u00e9gions","D\u00e9partements"), - type_logement = "collectif" - ){ - indic<-c("Encours - Appartements", - "Mises en vente - Appartements", - "Ventes - Appartements", - "PrixM2 - Appartements") - if (type_logement=="individuel") { - indic<- c("Encours - Maisons", - "Mises en vente - Maisons", - "Ventes - Maisons", - "PrixPar - Maisons") - } - input<-indic_ecln %>% - dplyr::filter(.data$Indicateur %in% indic, - .data$TypeZone %in% type_zone, - .data$TypeIndicateur=="Cumul annuel", - .data$Periode==max(.data$Periode)) %>% - dplyr::mutate(Indicateur=stringr::str_split_fixed(.data$Indicateur,"-",2)[,1]) - - nombre_zone <- length(unique(input$CodeZone)) - nombre_fr_dep_reg <- length(unique(input %>% dplyr::filter(.data$TypeZone %in% c("R\u00e9gions","D\u00e9partements")) %>% dplyr::pull(.data$CodeZone))) - res<- input %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$Indicateur,.data$Valeur) %>% - tidyr::spread(.data$Indicateur,.data$Valeur) %>% - dplyr::full_join( - input %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$Indicateur,.data$TauxEvolution12Mois) %>% - tidyr::spread(.data$Indicateur,.data$TauxEvolution12Mois), - by=c("TypeZone","Zone") - ) %>% - dplyr::arrange(.data$Zone) %>% - dplyr::select(2,6,10,4,8,3,7,5,9) %>% - knitr::kable("html",col.names=c("Zone","Sur les 12 derniers mois","Evolution sur un an (en %)", - "Sur les 12 derniers mois","Evolution sur un an (en %)", - "En fin de p\u00e9riode","Evolution sur un an (en %)", - "Prix moyen sur les 12 derniers mois (en €)","Evolution sur un an (en %)"), - digits=c(0,0,1,0,1,0,1,0,1), - format.args=list(big.mark=" ",decimal.mark=",")) %>% - kableExtra::kable_styling(font_size = 12) %>% - kableExtra::row_spec(1:2, bold = T, background = "#f0f0f5") %>% - kableExtra::add_header_above(c(" "=1, "Ventes" = 2, "Mises en vente" = 2, "Encours" = 2,"Prix au m2"=2)) %>% - kableExtra::add_indent(c(3:nombre_zone)) - if("ABC" %in% type_zone){ - res<-res %>% - kableExtra::row_spec(nombre_fr_dep_reg:nombre_zone, bold = T, background = "#bebece") - } - return(res) -} diff --git a/R/tableau_synthese_trimestrielle.R b/R/tableau_synthese_trimestrielle.R deleted file mode 100644 index df9cc90..0000000 --- a/R/tableau_synthese_trimestrielle.R +++ /dev/null @@ -1,56 +0,0 @@ -#' Création du tableau de synthèse trimestrielle -#' -#' @param data Le dataframe. -#' @param type_logement Collectifs ou individuels. -#' -#' @return un tableau kable -#' @export -#' @importFrom dplyr filter mutate select full_join arrange -#' @importFrom kableExtra kable_styling row_spec add_header_above -#' @importFrom knitr kable -#' @importFrom stringr str_split_fixed -#' @importFrom tidyr spread -tableau_synthese_trimestrielle<-function(data = indic_ecln, - type_logement="collectif"){ - - indic<-c("Encours - Appartements", - "Mises en vente - Appartements", - "Ventes - Appartements", - "PrixM2 - Appartements") - if (type_logement=="individuel") { - indic<- c("Encours - Maisons", - "Mises en vente - Maisons", - "Ventes - Maisons", - "PrixPar - Maisons") - } - indic_ecln %>% - dplyr::filter(.data$Indicateur %in% indic, - .data$TypeZone %in% c("France","Régions"), - .data$TypeIndicateur != "Cumul annuel", - .data$Periode==max(.data$Periode)) %>% - dplyr::mutate(Indicateur=str_split_fixed(.data$Indicateur,"-",2)[,1]) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$Indicateur,.data$Valeur) %>% - tidyr::spread(.data$Indicateur,.data$Valeur) %>% - dplyr::full_join( - indic_ecln %>% - dplyr::filter(.data$Indicateur %in% indic, - .data$TypeZone %in% c("France","Régions"), - .data$TypeIndicateur!="Cumul annuel", - .data$Periode==max(.data$Periode)) %>% - dplyr::mutate(Indicateur=stringr::str_split_fixed(.data$Indicateur,"-",2)[,1]) %>% - dplyr::select(.data$TypeZone,.data$Zone,.data$Indicateur,.data$TauxEvolution12Mois) %>% - spread(.data$Indicateur,.data$TauxEvolution12Mois), - by=c("TypeZone","Zone") - ) %>% - dplyr::arrange(.data$Zone) %>% - dplyr::select(2,6,10,4,8,3,7,5,9) %>% - knitr::kable("html",col.names=c("Zone","Sur le dernier trimestre","Evolution sur un an (en %)", - "Sur le dernier trimestre","Evolution sur un an (en %)", - "En fin de p\u00e9riode","Evolution sur un an (en %)", - "Prix moyen sur le dernier trimestre (en €)","Evolution sur un an (en %)"), - digits=c(0,0,1,0,1,0,1,0,1), - format.args=list(big.mark=" ",decimal.mark=",")) %>% - kableExtra::kable_styling(font_size = 12) %>% - kableExtra::row_spec(1:2, bold = T, background = "#f0f0f5") %>% - kableExtra::add_header_above(c(" "=1, "Ventes" = 2, "Mises en vente" = 2, "Encours" = 2,"Prix au m2"=2)) -} diff --git a/README.md b/README.md index 047f34e..00ae22f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# propre.ecln - +# propre.ecln + package de création de la publication conjoncturelle ecln \ No newline at end of file diff --git a/data-raw/data-raw-ecln-sas-R.R b/data-raw/data-raw-ecln-sas-R.R index d797147..e3de6d5 100644 --- a/data-raw/data-raw-ecln-sas-R.R +++ b/data-raw/data-raw-ecln-sas-R.R @@ -23,11 +23,11 @@ conflict_prefer("setdiff", "dplyr") source("R/FormatDate.R") trimestre <- fs::dir_ls(path = "extdata", type = "directory") %>% - stringr::str_replace_all("extdata/","") %>% + stringr::str_replace_all("extdata/", "") %>% max() trimestre_date <- FormatDate(trimestre, Periodicite = "Trim", sep = "T") -trimestre_min <- FormatCaractere(trimestre_date-years(5)-months(3)) +trimestre_min <- FormatCaractere(trimestre_date - years(5) - months(3)) file_sas <- glue("extdata/{trimestre}/stat_info_data_regionaux.sas7bdat") file_redressement <- glue("extdata/{trimestre}/{trimestre}rd1-commercialisation-lgts-neufs.xls") @@ -63,22 +63,22 @@ indic_ecln <- ECLN %>% summarise(mev_t = sum(mev_t, na.rm = T)) %>% ungroup() %>% full_join(ECLN %>% - select(DEPCOM = code_insee, Periode = trimestre_enquete, everything()) %>% - filter(Periode >= trimestre_min) %>% - mutate( - nb_lgt_inv = nb_lgt_inv_t1 + nb_lgt_inv_t2 + nb_lgt_inv_t3 + nb_lgt_inv_t4 + nb_lgt_inv_t5 + nb_lgt_inv_t6, - nb_hors_resa_inv = nb_resa - nb_lgt_inv - ) %>% - group_by(id_type_lgt, DEPCOM, Periode) %>% - summarise( - nb_resa = sum(nb_resa, na.rm = T), - nb_resa_inv = sum(nb_lgt_inv, na.rm = T), - nb_hors_resa_inv = sum(nb_hors_resa_inv, na.rm = T), - stock_fin = sum(stock_fin, na.rm = T), - prix = sum(prix, na.rm = T), - surface = sum(surface, na.rm = T) - ) %>% - ungroup()) %>% + select(DEPCOM = code_insee, Periode = trimestre_enquete, everything()) %>% + filter(Periode >= trimestre_min) %>% + mutate( + nb_lgt_inv = nb_lgt_inv_t1 + nb_lgt_inv_t2 + nb_lgt_inv_t3 + nb_lgt_inv_t4 + nb_lgt_inv_t5 + nb_lgt_inv_t6, + nb_hors_resa_inv = nb_resa - nb_lgt_inv + ) %>% + group_by(id_type_lgt, DEPCOM, Periode) %>% + summarise( + nb_resa = sum(nb_resa, na.rm = T), + nb_resa_inv = sum(nb_lgt_inv, na.rm = T), + nb_hors_resa_inv = sum(nb_hors_resa_inv, na.rm = T), + stock_fin = sum(stock_fin, na.rm = T), + prix = sum(prix, na.rm = T), + surface = sum(surface, na.rm = T) + ) %>% + ungroup()) %>% gather(Indicateur, Valeur, mev_t:surface) %>% mutate( Periode = factor(Periode), @@ -89,11 +89,11 @@ indic_ecln <- ECLN %>% Indicateur = str_c(Indicateur, " - ", id_type_lgt) ) %>% select(-id_type_lgt) %>% - mutate(Valeur = ifelse(is.na(Valeur),0,Valeur)) %>% + mutate(Valeur = ifelse(is.na(Valeur), 0, Valeur)) %>% passer_au_cog_a_jour(code_commune = DEPCOM, aggrege = T, garder = F) %>% right_join(communes %>% select(DEPCOM)) %>% complete(DEPCOM, Periode, Indicateur, - fill = list(Valeur = 0) + fill = list(Valeur = 0) ) %>% filter(!is.na(Indicateur), !is.na(Periode)) %>% passer_au_cog_a_jour(code_commune = DEPCOM, aggrege = T, garder = T) %>% @@ -124,8 +124,8 @@ taux_redressement <- indic_ecln %>% indic_ecln <- indic_ecln %>% left_join(taux_redressement) %>% mutate(Valeur = ifelse(Periode == max(Periode) & Indicateur %in% unique(valeur_redressees$Indicateur), - Valeur * taux_redressement, - Valeur + Valeur * taux_redressement, + Valeur )) %>% select(-taux_redressement, -REG) %>% mutate_if(is.character, as.factor) @@ -162,8 +162,8 @@ indic_ecln <- indic_ecln %>% indic_ecln_abc <- indic_ecln %>% filter(TypeZone == "Communes", CodeZone %in% (liste_zone %>% - filter(str_detect(REG, "52"), TypeZone == "Communes") %>% - pull(CodeZone))) %>% + filter(str_detect(REG, "52"), TypeZone == "Communes") %>% + pull(CodeZone))) %>% left_join(zonage_abc, by = c("CodeZone" = "DEPCOM")) %>% select(zonage_abc, Periode, Indicateur, Valeur) %>% rename(CodeZone = zonage_abc) %>% @@ -193,23 +193,22 @@ indic_ecln_abc <- indic_ecln %>% # Aggrégation de l'ensemble des calculs sur les zones ----------------------------------- -indic_ecln <- bind_rows(indic_ecln, indic_ecln_abc)%>% +indic_ecln <- bind_rows(indic_ecln, indic_ecln_abc) %>% arrange(TypeZone, Zone, CodeZone, Indicateur, Periode) %>% filter(TypeZone != "Communes") -rm(list=setdiff(ls(),c("indic_ecln","FormatDate"))) +rm(list = setdiff(ls(), c("indic_ecln", "FormatDate"))) # Utilisation du package dtplyr pour la performance -indicateurs_non_sommables <- str_subset(levels(indic_ecln$Indicateur),"Encours") +indicateurs_non_sommables <- str_subset(levels(indic_ecln$Indicateur), "Encours") indic_ecln <- indic_ecln %>% lazy_dt() %>% group_by(TypeZone, Zone, CodeZone, Indicateur) %>% - mutate(Valeur_cumul = Valeur + lag(Valeur) + lag(Valeur, 2) + lag(Valeur, 3) - ) %>% + mutate(Valeur_cumul = Valeur + lag(Valeur) + lag(Valeur, 2) + lag(Valeur, 3)) %>% ungroup() %>% - mutate(Valeur_cumul=ifelse(Indicateur %in% indicateurs_non_sommables,Valeur,Valeur_cumul)) %>% + mutate(Valeur_cumul = ifelse(Indicateur %in% indicateurs_non_sommables, Valeur, Valeur_cumul)) %>% as_tibble() diff --git a/inst/rmarkdown/templates/ecln_conjoncture/skeleton/.gitignore b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/.gitignore new file mode 100644 index 0000000..fbad71c --- /dev/null +++ b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/.gitignore @@ -0,0 +1,2 @@ +skeleton.html +www/* diff --git a/inst/rmarkdown/templates/ecln_conjoncture/skeleton/footer.html b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/footer.html new file mode 100644 index 0000000..f9342be --- /dev/null +++ b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/footer.html @@ -0,0 +1,37 @@ + +<hr /> +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> + +<p style="font-size:150%;text-align:center;color:grey";>La commercialisation des logements neufs en Pays de la Loire</p> + +<div class="col-md-6"> + +<p style="text-align: left;">Rédaction et mise en forme : Maël THEULIERE +<a href="mael.theuliere@developpement-durable.gouv.fr" class="fa fa-envelope"></a> + <a href="tel: 0272747450" class="fa fa-phone"></a></p> +<p style="text-align: center;">Une production du</p> +<center><img src="www/Logo_datalab.svg", width="200"></center> + +</div> + +<div class="col-md-6"> + +<p style="text-align: left;">Direction régionale de l’environnement de l’aménagement et du logement</p> + +<p style="text-align: left;">Service connaissance des territoires et évaluation </p> + +<p style="text-align: left;">Division de l'observation,des études et des statistiques</p> + +<p style="text-align: left;">5 rue Françoise Giroud -CS1632644263 Nantes Cedex 2</p> + +<p style="text-align: left;">Tél. 02 72 74 73 00</p> + +<p style="text-align: left;">Directrice de la publication : Annick Bonneville</p> + +<p style="text-align: left;">ISSN : 2109-0025</p> + +<p style="text-align: left;">©DREAL 2019</p> +</div> + +<hr /> + diff --git a/inst/rmarkdown/templates/ecln_conjoncture/skeleton/header.html b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/header.html new file mode 100644 index 0000000..4c300d4 --- /dev/null +++ b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/header.html @@ -0,0 +1,9 @@ +<div class="row"> + +<div class="col-md-4"> +<a> +<img src="www/52-pays-de-la-loire-RVB.png" width="215px"> +</a> +</div> + +</div> diff --git a/inst/rmarkdown/templates/ecln_conjoncture/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/skeleton.Rmd new file mode 100644 index 0000000..3723630 --- /dev/null +++ b/inst/rmarkdown/templates/ecln_conjoncture/skeleton/skeleton.Rmd @@ -0,0 +1,316 @@ +--- +title: "Commercialisation des logements neufs" +author: "XX - Dreal Pays de la Loire - XX@developpement-durable.gouv.fr" +date: "`r Sys.Date()`" +output: + gouvdown::html_gouv: + toc: TRUE + logo: "prefecture_r52" + include: + after_body: footer.html +params: + region: "52" + abc: FALSE +editor_options: + chunk_output_type: console + markdown: + wrap: 72 +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set( + echo = FALSE, message = FALSE, warning = FALSE, error = FALSE, + fig.height = 12, + fig.width = 12, + width = 100 +) +library(propre.ecln) + + +set_theme() + +mygrid <- data.frame( + code = c("FRMETRO", "52", "53", "49", "44", "Zone C", "85", "72", "Zone B2", "Zone B1"), + name = c("France métropolitaine", "Pays de la Loire", "Mayenne", "Maine-et-Loire", "Loire-Atlantique", "Zone C", "Vendée", "Sarthe", "Zone B2", "Zone B1"), + row = c(1, 1, 2, 2, 2, 4, 3, 3, 4, 4), + col = c(1, 2, 3, 2, 1, 3, 2, 1, 2, 1), + stringsAsFactors = FALSE +) +if (!params$abc) { + mygrid <- mygrid %>% dplyr::filter(!(code %in% c("Zone C", "Zone B1", "Zone B2"))) +} +caption <- "Source : ECLN \nCalculs : DREAL Pays de la Loire\nNombre de ventes et mises en ventes \n sur les 12 derniers mois\nEncours en fin de période" +caption_appartements <- "Source : ECLN \nCalculs : DREAL Pays de la Loire\nNombre de ventes et mises en ventes d'appartements \n sur les 12 derniers mois\nEncours en fin de période" +caption_maisons <- "Source : ECLN \nCalculs : DREAL Pays de la Loire\nNombre de ventes et mises en ventes de maisons \n sur les 12 derniers mois\nEncours en fin de période \n Les résultats de la Mayenne et de la Sarthe sont soumis au secret statistique" +caption_carte_maisons <- "Source : ECLN \nCalculs : DREAL Pays de la Loire\nNombre de ventes et mises en ventes de maisons \n sur les 12 derniers mois\nEncours en fin de période" +captionprix <- "Source : ECLN \nCalculs : DREAL Pays de la Loire\nPrix moyen observé sur les 12 derniers mois" +captionprix_maisons <- "Source : ECLN \nCalculs : DREAL Pays de la Loire\nPrix moyen observé sur les 12 derniers mois \nLes résultats de la Mayenne et de la zone C sont sous le seuil du secret statistique" + +typezone <- c("France", "R\u00e9gions", "D\u00e9partements") + +if (params$abc) { + typezone <- c("France", "R\u00e9gions", "D\u00e9partements", "ABC") +} + +indic_ecln <- data_prep( + reg = params$region, + abc = params$abc +) +``` + +## Synthèse + +### Ventes de logements neufs + + +<div class = "row"> + +<div class = "col-md-5"> + +<hr> + +`r creer_chiffres_clefs_ecln()` + +<hr> + +A COMPLETER + +</div> + +::: {.col-md-7} +<br> <br> <br> <br> <br> + +```{r, logements,fig.height=5, fig.width=6} +creer_graphique_evolution_trim( + indicateur = "Ventes - Logements", + titre = "Ventes de logements neufs \nen Pays de la Loire" +) +``` +::: + +</div> + + + + +### Ventes d'appartements + +<div class = "row"> + +::: {.col-md-7} +<br> <br> <br> <br> <br> + +```{r, logements_coll,fig.height=5, fig.width=6} +creer_graphique_evolution_trim( + indicateur = "Ventes - Appartements", + titre = "Ventes d'appartements neufs \nen Pays de la Loire" +) +``` +::: + +<div class = "col-md-5"> + +<hr> + +`r creer_chiffres_clefs_ecln(type_logement = 'Appartements')` + +<hr> + +A COMPLETER +</div> + +::: {.col-md-5} +A COMPLETER + +::: + + + +### Ventes de maisons + +<div class = "row"> + +::: {.col-md-7} +```{r logements_indiv,fig.height=5, fig.width=6} +creer_graphique_evolution_trim( + indicateur = "Ventes - Maisons", + titre = "Ventes de maisons neuves \nen Pays de la Loire" +) +``` +::: + +<div class = "col-md-5"> + +<hr> + +`r creer_chiffres_clefs_ecln(type_logement = 'Maisons')` + +<hr> + +A COMPLETER + +</div> + +</div> + + + + +## Le marché du collectif + +### Les chiffres clefs + +#### Chiffres trimestriels + +```{r collectiftableautrim} +creer_tableau_synthese_trimestrielle(type_logement = "collectif") +``` + +#### Chiffres cumulés sur les 4 derniers trimestres + +```{r collectiftableaucumul} +creer_tableau_synthese_annuel( + type_logement = "collectif", + type_zone = typezone +) +``` + + + +### Les principales évolutions {.tabset} + +#### Les comparaisons sur un an + +```{r collectifevolution0} +creer_graphique_evolution_annuelle( + type_logement = "collectif", + type_zone = typezone, + titre = "Evolution des ventes et mises en vente d'appartements neufs", + bas_de_page = caption, + type_facet = "grille" +) +``` + +#### Les séries temporelles + +```{r collectifevolution} +creer_graphique_series_temporelles( + type_logement = "Appartements", + type_zone = typezone, + titre = "Evolution des ventes et mises en vente d'appartements neufs sur 12 mois glissants", + bas_de_page = caption, + type_facet = "grille" +) +``` + +### L'investissement locatif + +```{r collectifIL} +creer_graphique_investissement_locatif( + type_logement = "Appartements", + type_zone = typezone, + titre = "Evolution des ventes d'appartements neufs sur 12 mois glissants <span style = 'color:#D66C58;'>en investissement locatif</span> et <span style = 'color:#FFBCB3;'>hors investissement locatif</span>", + bas_de_page = caption, + type_facet = "grille" +) + + ggplot2::theme(plot.title = ggtext::element_textbox_simple(size = 20, lineheight = 1.2)) + + ggplot2::guides( + colour = F, + order = 0, + fill = F + ) +``` + +### L'évolution des prix + +```{r collectifprix} +creer_graphique_series_temporelles_prix( + type_logement = "Appartements", + type_zone = typezone, + titre = "Evolution du prix au m2 moyen des appartements neufs en euros sur 12 mois glissants", + bas_de_page = captionprix, + type_facet = "grille" +) +``` + + + + +## Le marché de l'individuel + +### Les chiffres clefs + +#### Chiffres trimestriels + +```{r individueltableautrim} +creer_tableau_synthese_trimestrielle(type_logement = "individuel") +``` + +#### Chiffres cumulés sur les 4 derniers trimestres + +```{r individueltableaucumul} +creer_tableau_synthese_annuel( + type_logement = "individuel", + type_zone = typezone +) +``` + + + +### Les principales évolutions {.tabset} + +#### Les comparaisons sur un an + +```{r individuelevolution0} +creer_graphique_evolution_annuelle( + type_logement = "individuel", + type_zone = typezone, + titre = "Evolution des ventes et mises en vente de maisons neuves", + bas_de_page = caption, + type_facet = "grille" +) +``` + +#### Les séries temporelles + +```{r individuelevolution} +creer_graphique_series_temporelles( + type_logement = "Maisons", + type_zone = typezone, + titre = "Evolution des ventes et mises en vente de maisons neuves sur 12 mois glissants", + bas_de_page = caption, + type_facet = "grille" +) +``` + +### L'investissement locatif + +```{r individuelIL} +creer_graphique_investissement_locatif( + type_logement = "Maisons", + type_zone = typezone, + titre = "Evolution des ventes de maisons neuves sur 12 mois glissants <span style = 'color:#D66C58;'>en investissement locatif</span> et <span style = 'color:#FFBCB3;'>hors investissement locatif</span>", + bas_de_page = caption, + type_facet = "grille" +) + + ggplot2::theme(plot.title = ggtext::element_textbox_simple(size = 20, lineheight = 1.2)) + + ggplot2::guides( + colour = F, + order = 0, + fill = F + ) +``` + +### L'évolution des prix + +```{r individuelprix} +creer_graphique_series_temporelles_prix( + type_logement = "Maisons", + type_zone = typezone, + titre = "Evolution du prix au m2 moyen des maisons neuves en euros sur 12 mois glissants", + bas_de_page = captionprix, + type_facet = "grille" +) +``` + + diff --git a/inst/rmarkdown/templates/ecln_conjoncture/template.yaml b/inst/rmarkdown/templates/ecln_conjoncture/template.yaml new file mode 100644 index 0000000..e541e07 --- /dev/null +++ b/inst/rmarkdown/templates/ecln_conjoncture/template.yaml @@ -0,0 +1,4 @@ +name: Publication conjoncturelle commercialisation des logements neufs +description: > + A description of the template +create_dir: FALSE diff --git a/man/creer_chiffres_clefs_ecln.Rd b/man/creer_chiffres_clefs_ecln.Rd new file mode 100644 index 0000000..5be40b5 --- /dev/null +++ b/man/creer_chiffres_clefs_ecln.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/creer_chiffres_clefs.R +\name{creer_chiffres_clefs_ecln} +\alias{creer_chiffres_clefs_ecln} +\title{Chiffres clefs pour la publication} +\usage{ +creer_chiffres_clefs_ecln( + data = indic_ecln, + type_logement = "Logements", + indicateur = "Ventes", + type_indicateur = "Trimestriel" +) +} +\arguments{ +\item{data}{le dataframe avec les données ecln} + +\item{type_logement}{Appartements ou Maisons} + +\item{indicateur}{Ventes, Mises en vente ou encours} + +\item{type_indicateur}{cumul annuel ou valeur trimestrielle} +} +\value{ +du code html +} +\description{ +Chiffres clefs pour la publication +} diff --git a/man/creer_graphique_evolution_annuelle.Rd b/man/creer_graphique_evolution_annuelle.Rd index 2dc8809..44352a9 100644 --- a/man/creer_graphique_evolution_annuelle.Rd +++ b/man/creer_graphique_evolution_annuelle.Rd @@ -6,10 +6,12 @@ \usage{ creer_graphique_evolution_annuelle( data = indic_ecln, - type_zone = c("Régions", "Départements"), + type_zone = c("France", "Régions", "Départements"), type_logement = "collectif", titre = "", - bas_de_page = "" + bas_de_page = "", + type_facet = "classique", + ncol_facet = 4 ) } \arguments{ @@ -22,6 +24,10 @@ creer_graphique_evolution_annuelle( \item{titre}{Le titre du graphique.} \item{bas_de_page}{Le bas de page du graphique.} + +\item{type_facet}{type de facette : grille pour une matrice, geo pour une} + +\item{ncol_facet}{Le nombre de colonnes dans la facette.} } \value{ Un graphique ggplot2. diff --git a/man/graphique_evolution_trim.Rd b/man/creer_graphique_evolution_trim.Rd similarity index 78% rename from man/graphique_evolution_trim.Rd rename to man/creer_graphique_evolution_trim.Rd index 59d1e13..a8dbb1c 100644 --- a/man/graphique_evolution_trim.Rd +++ b/man/creer_graphique_evolution_trim.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/graphique_evolution_trim.R -\name{graphique_evolution_trim} -\alias{graphique_evolution_trim} +% Please edit documentation in R/creer_graphique_evolution_trim.R +\name{creer_graphique_evolution_trim} +\alias{creer_graphique_evolution_trim} \title{graphique sur un territoire sur un indicateur en moyenne annuelle et valeur trimestrielle} \usage{ -graphique_evolution_trim( +creer_graphique_evolution_trim( data = indic_ecln, indicateur = "Ventes - Logements", zone = "Pays de la Loire", diff --git a/man/graphique_investissement_locatif.Rd b/man/creer_graphique_investissement_locatif.Rd similarity index 73% rename from man/graphique_investissement_locatif.Rd rename to man/creer_graphique_investissement_locatif.Rd index 6737a59..f08fe0e 100644 --- a/man/graphique_investissement_locatif.Rd +++ b/man/creer_graphique_investissement_locatif.Rd @@ -1,17 +1,19 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/graphique_investissement_locatif.R -\name{graphique_investissement_locatif} -\alias{graphique_investissement_locatif} +% Please edit documentation in R/creer_graphique_investissement_locatif.R +\name{creer_graphique_investissement_locatif} +\alias{creer_graphique_investissement_locatif} \title{Graphique d'évolution de l'investissement locatif} \usage{ -graphique_investissement_locatif( +creer_graphique_investissement_locatif( data = indic_ecln, type_logement = "Appartements", type_zone = c("Régions", "Départements"), type_indicateur = "Cumul annuel", titre = "", soustitre = "", - bas_de_page = "" + bas_de_page = "", + type_facet = "classique", + ncol_facet = 4 ) } \arguments{ diff --git a/man/graphique_series_temporelles.Rd b/man/creer_graphique_series_temporelles.Rd similarity index 73% rename from man/graphique_series_temporelles.Rd rename to man/creer_graphique_series_temporelles.Rd index a3c6b09..759c128 100644 --- a/man/graphique_series_temporelles.Rd +++ b/man/creer_graphique_series_temporelles.Rd @@ -1,16 +1,17 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/graphique_series_temporelles.R -\name{graphique_series_temporelles} -\alias{graphique_series_temporelles} +% Please edit documentation in R/creer_graphique_series_temporelles.R +\name{creer_graphique_series_temporelles} +\alias{creer_graphique_series_temporelles} \title{graphique en série temporelle à facette} \usage{ -graphique_series_temporelles( +creer_graphique_series_temporelles( data = indic_ecln, type_logement = "Appartements", indicateurs = c("Encours", "Mises en vente", "Ventes"), - type_zone = c("Régions", "Départements"), + type_zone = c("France", "Régions", "Départements"), titre = "", bas_de_page = "", + type_facet = "classique", ncol_facet = 4 ) } diff --git a/man/graphique_series_temporelles_prix.Rd b/man/creer_graphique_series_temporelles_prix.Rd similarity index 71% rename from man/graphique_series_temporelles_prix.Rd rename to man/creer_graphique_series_temporelles_prix.Rd index 745fe32..ddf3e9c 100644 --- a/man/graphique_series_temporelles_prix.Rd +++ b/man/creer_graphique_series_temporelles_prix.Rd @@ -1,16 +1,18 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/graphique_series_temporelles_prix.R -\name{graphique_series_temporelles_prix} -\alias{graphique_series_temporelles_prix} +% Please edit documentation in R/creer_graphique_series_temporelles_prix.R +\name{creer_graphique_series_temporelles_prix} +\alias{creer_graphique_series_temporelles_prix} \title{graphique sur l'évolution du prix de vente des biens.} \usage{ -graphique_series_temporelles_prix( +creer_graphique_series_temporelles_prix( data = indic_ecln, type_logement = "Appartements", type_zone = c("Régions", "Départements"), type_indicateur = "Cumul annuel", titre = "", - bas_de_page = "" + bas_de_page = "", + type_facet = "classique", + ncol_facet = 4 ) } \arguments{ diff --git a/man/tableau_synthese_annuel.Rd b/man/creer_tableau_synthese_annuel.Rd similarity index 73% rename from man/tableau_synthese_annuel.Rd rename to man/creer_tableau_synthese_annuel.Rd index 680cec6..193a484 100644 --- a/man/tableau_synthese_annuel.Rd +++ b/man/creer_tableau_synthese_annuel.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/tableau_synthese_annuelle.R -\name{tableau_synthese_annuel} -\alias{tableau_synthese_annuel} +% Please edit documentation in R/creer_tableau_synthese_annuelle.R +\name{creer_tableau_synthese_annuel} +\alias{creer_tableau_synthese_annuel} \title{tableau de synthèse des données en cumul annuel} \usage{ -tableau_synthese_annuel( +creer_tableau_synthese_annuel( data = indic_ecln, type_zone = c("France", "Régions", "Départements"), type_logement = "collectif" diff --git a/man/tableau_synthese_trimestrielle.Rd b/man/creer_tableau_synthese_trimestrielle.Rd similarity index 53% rename from man/tableau_synthese_trimestrielle.Rd rename to man/creer_tableau_synthese_trimestrielle.Rd index 99bc62e..cc7c583 100644 --- a/man/tableau_synthese_trimestrielle.Rd +++ b/man/creer_tableau_synthese_trimestrielle.Rd @@ -1,10 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/tableau_synthese_trimestrielle.R -\name{tableau_synthese_trimestrielle} -\alias{tableau_synthese_trimestrielle} +% Please edit documentation in R/creer_tableau_synthese_trimestrielle.R +\name{creer_tableau_synthese_trimestrielle} +\alias{creer_tableau_synthese_trimestrielle} \title{Création du tableau de synthèse trimestrielle} \usage{ -tableau_synthese_trimestrielle(data = indic_ecln, type_logement = "collectif") +creer_tableau_synthese_trimestrielle( + data = indic_ecln, + type_logement = "collectif" +) } \arguments{ \item{data}{Le dataframe.} diff --git a/man/en_trimestre.Rd b/man/en_trimestre.Rd new file mode 100644 index 0000000..ad618ef --- /dev/null +++ b/man/en_trimestre.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/creer_chiffres_clefs.R +\name{en_trimestre} +\alias{en_trimestre} +\title{Converti une date en trimestre} +\usage{ +en_trimestre(date) +} +\arguments{ +\item{date}{une date} +} +\value{ +une chaine de caractère +} +\description{ +Converti une date en trimestre +} diff --git a/man/format_fr_nb.Rd b/man/format_fr_nb.Rd new file mode 100644 index 0000000..9522ef9 --- /dev/null +++ b/man/format_fr_nb.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/creer_chiffres_clefs.R +\name{format_fr_nb} +\alias{format_fr_nb} +\title{Fonction utilitaire de formatage de nombre pour le francais} +\usage{ +format_fr_nb(x, dec = 1, big_mark, sign = FALSE) +} +\arguments{ +\item{x}{un nombre à formater en français} + +\item{dec}{un entier désignant le nombre de chiffres après la virgule souhaité (1 par défaut)} + +\item{big_mark}{le séparateur des milliers} + +\item{sign}{TRUE pour avoir le signe +/-} +} +\value{ +une chaîne de texte avec transformation de la décimale en virgule et insertion d'un caractère spécifié via big_mark au niveau du séparateur de milliers +} +\description{ +fonction utilitaire de formatage de nombre pour le francais +} diff --git a/man/format_fr_pct.Rd b/man/format_fr_pct.Rd new file mode 100644 index 0000000..aaffb4b --- /dev/null +++ b/man/format_fr_pct.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/creer_chiffres_clefs.R +\name{format_fr_pct} +\alias{format_fr_pct} +\title{Fonction utilitaire de formatage en pourcentage pour le francais} +\usage{ +format_fr_pct(x, dec = 1, sign = TRUE) +} +\arguments{ +\item{x}{un nombre à formater en pourcentage} + +\item{dec}{un entier désignant le nombre de chiffres après la virgule souhaité (1 par défaut)} + +\item{sign}{TRUE pour avoir le signe +/-} +} +\value{ +une chaîne de texte, x \%, avec transformation de la décimale en virgule et insertion d'un espace insécable +} +\description{ +fonction utilitaire de formatage en pourcentage pour le francais +} diff --git a/man/indic_ecln.Rd b/man/indic_ecln.Rd index c0bf90f..a781d74 100644 --- a/man/indic_ecln.Rd +++ b/man/indic_ecln.Rd @@ -6,7 +6,7 @@ \alias{indic_ecln} \title{Table contenant les différents indicateurs de la source ecln utiles pour la publication.} \format{ -Table de 92664 lignes et 10 colonnes: +Table de 1596672 lignes et 9 colonnes: \describe{ \item{TypeZone}{Type de territoire} \item{CodeZone}{Code du territoire} diff --git a/man/set_theme.Rd b/man/set_theme.Rd new file mode 100644 index 0000000..d31309b --- /dev/null +++ b/man/set_theme.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_theme.R +\name{set_theme} +\alias{set_theme} +\title{Definir le theme par defaut des graphiques de la publication} +\usage{ +set_theme() +} +\value{ +une fonction +} +\description{ +Definir le theme par defaut des graphiques de la publication +} +\examples{ +set_theme() +} -- GitLab