Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
propre.ecln
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DREAL Pays de la Loire
Centre de Services de la Donnée
propre.ecln
Commits
0d7a86ac
Commit
0d7a86ac
authored
10 months ago
by
Juliette Engelaere-Lefebvre
Browse files
Options
Downloads
Patches
Plain Diff
test mise en page messages sur données manquantes
parent
a5a2cf06
No related branches found
No related tags found
No related merge requests found
Pipeline
#382469
failed
10 months ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/creer_graphique_series_temporelles_prix.R
+30
-35
30 additions, 35 deletions
R/creer_graphique_series_temporelles_prix.R
with
30 additions
and
35 deletions
R/creer_graphique_series_temporelles_prix.R
+
30
−
35
View file @
0d7a86ac
#' 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_logement
"Logements", "
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.
...
...
@@ -11,7 +11,7 @@
#'
#' @return Un graphique ggplot2.
#' @export
#' @importFrom dplyr filter mutate group_by summarise select case_when
#' @importFrom dplyr filter mutate group_by summarise select case_when
arrange
#' @importFrom forcats fct_drop
#' @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
...
...
@@ -25,42 +25,40 @@ creer_graphique_series_temporelles_prix <- function(data = indic_ecln,
bas_de_page
=
""
,
type_facet
=
"classique"
,
ncol_facet
=
3
)
{
indic
<-
c
(
"PrixM2 - Logements"
)
if
(
type_logement
==
"Maisons"
)
{
indic
<-
c
(
"PrixM2 - Maisons"
)
}
if
(
type_logement
==
"Appartements"
)
{
indic
<-
c
(
"PrixM2 - Appartements"
)
}
indic
<-
paste0
(
"PrixM2 - "
,
type_logement
)
data_prep
<-
data
%>%
# mutate(Valeur = case_when(
# CodeZone %in% c("53", "72") ~ NA_real_,
# year(Periode) %in% c(2018, 2019) & CodeZone == "49" ~ NA_real_,
# TRUE ~ Valeur)) %>%
dplyr
::
filter
(
# .data$Periode >= (max(.data$Periode) - months(42)),
.data
$
Indicateur
%in%
indic
,
.data
$
TypeIndicateur
==
type_indicateur
,
.data
$
TypeZone
%in%
type_zone
)
%>%
# COGiter::filtrer_cog(reg = "52", garder_supra = ">") %>%
dplyr
::
mutate
(
Zone
=
forcats
::
fct_drop
(
.data
$
Zone
),
Indicateur
=
stringr
::
str_split_fixed
(
.data
$
Indicateur
,
" - "
,
2
)[,
1
]
)
ymoy
<-
0.5
*
(
min
(
data_prep
$
Valeur
,
na.rm
=
TRUE
)
+
max
(
data_prep
$
Valeur
,
na.rm
=
TRUE
)
)
# creation des annotations pour zonages avec aucune donnée
annotations
<-
data_prep
%>%
dplyr
::
arrange
(
.data
$
Zone
,
.data
$
Periode
)
%>%
dplyr
::
filter
(
is.na
(
.data
$
Valeur
)
|
(
is.na
(
dplyr
::
lead
(
.data
$
Valeur
))
&
.data
$
Periode
!=
max
(
.data
$
Periode
)))
%>%
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
)
# Envisager un groupement différent pour gérer la discontinuité des période sans données ?
dplyr
::
summarise
(
x1
=
min
(
Periode
,
na.rm
=
TRUE
)
+
days
(
30
),
x2
=
max
(
Periode
,
na.rm
=
TRUE
),
y
=
dplyr
::
coalesce
(
dplyr
::
first
(
Valeur
,
na_rm
=
TRUE
),
ymoy
),
Indicateur
=
"message"
)
%>%
dplyr
::
mutate
(
mon_texte
=
dplyr
::
if_else
(
y
!=
ymoy
,
"Secret\nstatistique"
,
"Donn\u00e9es\nnon disponibles\nen raison\ndu secret\nstatistique"
))
p
<-
ggplot2
::
ggplot
(
data_prep
,
...
...
@@ -82,7 +80,8 @@ 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"
,
accuracy
=
1
))
+
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
,
...
...
@@ -98,22 +97,18 @@ creer_graphique_series_temporelles_prix <- function(data = indic_ecln,
if
(
nlevels
(
data_prep
$
Zone
)
>
1
)
{
if
(
type_facet
==
"classique"
)
{
p
<-
p
+
ggplot2
::
facet_wrap
(
~
.data
$
Zone
,
scales
=
"f
ree
"
,
ncol
=
ncol_facet
)
ggplot2
::
facet_wrap
(
~
.data
$
Zone
,
scales
=
"f
ixed
"
,
ncol
=
ncol_facet
)
}
if
(
type_facet
==
"grille"
)
{
p
<-
p
+
geofacet
::
facet_geo
(
~
Zone
,
grid
=
mygrid
,
scales
=
"f
ree
"
,
drop
=
TRUE
)
geofacet
::
facet_geo
(
~
Zone
,
grid
=
mygrid
,
scales
=
"f
ixed
"
,
drop
=
TRUE
)
}
}
p
<-
p
+
ggplot2
::
geom_text
(
data
=
annotations
,
ggplot2
::
aes
(
x
=
x
,
y
=
y
,
label
=
mon_texte
),
color
=
"blue"
,
size
=
4
)
p
+
ggplot2
::
geom_text
(
data
=
annotations
,
ggplot2
::
aes
(
x
=
x1
,
y
=
y
,
label
=
mon_texte
),
color
=
"blue"
,
size
=
3
,
hjust
=
"left"
,
)
# ggplot2::scale_y_continuous(labels = scales::dollar_format(big.mark = " ", decimal_mark = ",", prefix = "", suffix = " \u20ac"))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment