Skip to content
Snippets Groups Projects
Commit a5a2cf06 authored by Daniel.Kalioudjoglou's avatar Daniel.Kalioudjoglou
Browse files

modification du graphique series_temporelles_prix

affichage de texte dans les graphiques vides
parent c1a69b7d
No related branches found
No related tags found
No related merge requests found
Pipeline #382465 failed
Package: propre.ecln
Title: Publication conjoncturelle sur la commercialisation de logement neufs
Title: Publication conjoncturelle sur la commercialisation de logement
neufs
Version: 0.0.0.9000
Authors@R: c(
person("Maël", "THEULIERE", , "mael.theuliere@gmail.com", role = c("aut", "cre"),
......@@ -7,7 +8,8 @@ Authors@R: c(
person("Daniel", "Kalioudjoglou", , "daniel.kalioudjoglou@developpement-durable.gouv.fr", role = "aut"),
person("Denis", "Douillard", , "denis.douillard@developpement-durable.gouv.fr", role = "aut")
)
Description: Template Rmarkdown et fonctions pour réaliser la publication trimestrielle sur la commercialisation de logement neufs.
Description: Template Rmarkdown et fonctions pour réaliser la publication
trimestrielle sur la commercialisation de logement neufs.
License: GPL (>= 3)
Depends:
R (>= 2.10)
......@@ -34,7 +36,8 @@ Imports:
scales,
sf,
stringr,
tidyr
tidyr,
utils
Remotes:
gitlab::dreal-datalab/drealdown,
gitlab::dreal-datalab/mapfactory,
......
......@@ -28,12 +28,14 @@ importFrom(dplyr,case_when)
importFrom(dplyr,distinct)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,pull)
importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(dplyr,slice_max)
importFrom(dplyr,summarise)
importFrom(drealdown,my_icon)
importFrom(forcats,fct_drop)
importFrom(forcats,fct_explicit_na)
......@@ -56,6 +58,7 @@ importFrom(ggplot2,geom_label)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_sf)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,guide_legend)
importFrom(ggplot2,guides)
......
......@@ -15,7 +15,6 @@
#' @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"),
......
......@@ -11,13 +11,12 @@
#'
#' @return Un graphique ggplot2.
#' @export
#' @importFrom dplyr filter mutate
#' @importFrom dplyr filter mutate group_by summarise select case_when
#' @importFrom forcats fct_drop
#' @importFrom ggplot2 ggplot aes geom_line geom_point theme scale_x_date scale_y_continuous labs facet_wrap element_line
#' @importFrom ggplot2 ggplot aes geom_line geom_point theme scale_x_date scale_y_continuous labs facet_wrap element_line geom_text
#' @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 = "Logements",
type_zone = c("R\u00e9gions", "D\u00e9partements"),
......@@ -44,6 +43,24 @@ creer_graphique_series_temporelles_prix <- function(data = indic_ecln,
Indicateur = stringr::str_split_fixed(.data$Indicateur, " - ", 2)[, 1]
)
# creation des annotations pour zonages avec aucune donnée
annotations <- data_prep %>%
dplyr::group_by(.data$Zone) %>%
dplyr::summarise(som_valeur = sum(.data$Valeur,na.rm=TRUE)) %>%
# dplyr::mutate(Zone= as.character(.data$Zone)) %>%
dplyr::mutate(
x = mean(range(data_prep$Periode)),
y = 4000,
Indicateur = "xx") %>%
dplyr::mutate(mon_texte = dplyr::case_when(
som_valeur == 0 ~ "Donn\u00e9es\nnon disponibles\nen raison\ndu secret\nstatistique",
TRUE ~ ""
)) %>%
dplyr::mutate(color_axe_y = dplyr::case_when(
som_valeur == 0 ~ "red",
TRUE ~ "black"
)) %>%
dplyr::select(-som_valeur)
p <- ggplot2::ggplot(
data_prep,
......@@ -56,13 +73,6 @@ creer_graphique_series_temporelles_prix <- function(data = indic_ecln,
)
) +
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",
legend.title = element_blank(),
panel.grid.major = element_line(color = "lightgrey", linetype = "solid"),
......@@ -72,7 +82,7 @@ creer_graphique_series_temporelles_prix <- function(data = indic_ecln,
axis.text.x = element_text(size=11, hjust=-0.1),
axis.line = element_line(size = 0.5, linetype = "solid")) +
ggplot2::scale_x_date(date_labels = "%y", expand = c(0, 0), date_breaks = "1 year") +
ggplot2::scale_y_continuous(labels = scales::dollar_format(big.mark = " ", decimal_mark = ",", prefix = "", suffix = " \u20ac")) +
ggplot2::scale_y_continuous(labels = scales::dollar_format(big.mark = " ", decimal_mark = ",", prefix = "", suffix = " \u20ac",accuracy = 1)) +
gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_fr") +
ggplot2::labs(
title = titre,
......@@ -82,6 +92,9 @@ creer_graphique_series_temporelles_prix <- function(data = indic_ecln,
color = "",
caption = bas_de_page
)
if (nlevels(data_prep$Zone) > 1) {
if (type_facet == "classique") {
p <- p +
......@@ -93,6 +106,18 @@ creer_graphique_series_temporelles_prix <- function(data = indic_ecln,
geofacet::facet_geo(~Zone, grid = mygrid, scales = "free", drop = TRUE)
}
}
p <- p +
ggplot2::geom_text(data = annotations,
ggplot2::aes(x = x,
y = y,
label = mon_texte),
color = "blue",
size = 4)
# ggplot2::scale_y_continuous(labels = scales::dollar_format(big.mark = " ", decimal_mark = ",", prefix = "", suffix = " \u20ac"))
return(p)
}
utils::globalVariables(
c("liste_zone", "indic_ecln", "%m-%","mygrid","params","Valeur",".")
c("liste_zone", "indic_ecln", "%m-%","mygrid","params",
"Valeur",".","mon_texte","som_valeur","x","y")
)
......@@ -25,4 +25,4 @@ usethis::use_package('tidyr')
usethis::use_r("tableau_synthese_trimestrielle")
attachment::att_amend_desc()
yusethis::use_r("globals.R")
usethis::use_r("globals.R")
......@@ -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 2535180 lignes et 9 colonnes:
Table de 96720 lignes et 10 colonnes:
\describe{
\item{TypeZone}{Type de territoire}
\item{CodeZone}{Code du territoire}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment