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
ae8b7c8f
Commit
ae8b7c8f
authored
3 years ago
by
Maël Theulière
Browse files
Options
Downloads
Patches
Plain Diff
initialisation `creer_carte_volume()`
parent
3469fff9
No related branches found
No related tags found
No related merge requests found
Pipeline
#132437
failed
3 years ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
NAMESPACE
+19
-0
19 additions, 0 deletions
NAMESPACE
R/creer_carte.R
+103
-0
103 additions, 0 deletions
R/creer_carte.R
man/creer_carte_volume.Rd
+37
-0
37 additions, 0 deletions
man/creer_carte_volume.Rd
with
159 additions
and
0 deletions
NAMESPACE
+
19
−
0
View file @
ae8b7c8f
...
...
@@ -3,6 +3,7 @@
export("%>%")
export(FormatCaractere)
export(FormatDate)
export(creer_carte_volume)
export(creer_chiffres_clefs_ecln)
export(creer_graphique_evolution_annuelle)
export(creer_graphique_evolution_trim)
...
...
@@ -14,6 +15,9 @@ export(creer_tableau_synthese_trimestrielle)
export(data_prep)
export(set_theme)
importFrom(COGiter,filtrer_cog)
importFrom(COGiter,filtrer_cog_geo)
importFrom(COGiter,list_epci_in_reg)
importFrom(COGiter,nom_zone)
importFrom(attempt,stop_if_not)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
...
...
@@ -21,8 +25,10 @@ importFrom(dplyr,case_when)
importFrom(dplyr,distinct)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,pull)
importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(drealdown,my_icon)
importFrom(forcats,fct_drop)
...
...
@@ -33,26 +39,36 @@ importFrom(geofacet,facet_geo)
importFrom(ggforce,geom_mark_circle)
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_flip)
importFrom(ggplot2,coord_sf)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_rect)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,geom_area)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_label)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_sf)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,guides)
importFrom(ggplot2,labs)
importFrom(ggplot2,margin)
importFrom(ggplot2,position_dodge)
importFrom(ggplot2,scale_size)
importFrom(ggplot2,scale_x_date)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,stat_sf_coordinates)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_set)
importFrom(ggspatial,annotation_north_arrow)
importFrom(ggspatial,annotation_scale)
importFrom(ggspatial,north_arrow_fancy_orienteering)
importFrom(glue,glue)
importFrom(gouvdown,gouv_colors)
importFrom(gouvdown,scale_color_gouv_discrete)
importFrom(gouvdown,scale_fill_gouv_discrete)
importFrom(gouvdown,theme_gouv)
importFrom(gouvdown,theme_gouv_map)
importFrom(grid,unit)
importFrom(kableExtra,add_header_above)
importFrom(kableExtra,add_indent)
...
...
@@ -68,9 +84,12 @@ importFrom(lubridate,year)
importFrom(lubridate,years)
importFrom(lubridate,ymd)
importFrom(magrittr,"%>%")
importFrom(mapfactory,fond_carto)
importFrom(rlang,.data)
importFrom(scales,dollar_format)
importFrom(scales,format_format)
importFrom(sf,st_bbox)
importFrom(sf,st_crs)
importFrom(stringr,str_c)
importFrom(stringr,str_replace)
importFrom(stringr,str_split_fixed)
...
...
This diff is collapsed.
Click to expand it.
R/creer_carte.R
0 → 100644
+
103
−
0
View file @
ae8b7c8f
#' Création de la carte en volume sur les indicateurs de commercialisation de logements neufs
#'
#' @param data Le dataframe.
#' @param code_region Le code de la région.
#' @param indicateurs Nom de l'indicateur.
#' @param type_logement Appartements ou Maisons.
#' @param titre Le titre du graphique.
#' @param titre_legende Le titre de la légende.
#' @param bas_de_page Le bas de page du graphique.
#'
#' @return une carte en ggplot2
#' @export
#' @importFrom COGiter filtrer_cog_geo list_epci_in_reg nom_zone
#' @importFrom dplyr filter rename left_join mutate
#' @importFrom ggplot2 ggplot geom_sf stat_sf_coordinates coord_sf scale_size theme element_rect element_blank labs
#' @importFrom ggspatial annotation_north_arrow north_arrow_fancy_orienteering annotation_scale
#' @importFrom gouvdown theme_gouv_map
#' @importFrom mapfactory fond_carto
#' @importFrom sf st_bbox st_crs
creer_carte_volume
<-
function
(
data
=
indic_ecln
,
code_region
=
params
$
reg
,
indicateurs
=
c
(
"Encours"
,
"Mises en vente"
,
"Ventes"
),
type_logement
=
"Appartements"
,
titre
=
""
,
titre_legende
=
""
,
bas_de_page
=
""
){
# On ne garde que les données des ventes pour réaliser les classes de valeur
indic
<-
paste0
(
indicateurs
,
" - "
,
type_logement
)
epci_geo
<-
COGiter
::
filtrer_cog_geo
(
reg
=
code_region
,
garder_supra
=
TRUE
)
$
epci
data_pour_carte
<-
data
%>%
dplyr
::
filter
(
Indicateur
%in%
indic
,
TypeZone
==
"EPCI"
)
%>%
dplyr
::
rename
(
EPCI
=
CodeZone
)
epci_reg
<-
COGiter
::
list_epci_in_reg
(
code_region
)
data_prep
<-
epci_geo
%>%
dplyr
::
left_join
(
data_pour_carte
)
%>%
dplyr
::
mutate
(
epci_reg
=
EPCI
%in%
epci_reg
,
indicateur_positif
=
Valeur
>
0
)
# Pour la Corse : définition de l'emprise de la carte : on veut 30 km de vide autour de la région et une carte plus large que haute
bbox_reg
<-
sf
::
st_bbox
(
data_prep
%>%
filter
(
epci_reg
))
fond_carte
<-
mapfactory
::
fond_carto
(
nom_reg
=
COGiter
::
nom_zone
(
"R\u00e9gions"
,
code_region
))
if
(
code_region
==
"94"
){
hauteur
=
bbox_reg
$
ymax
-
bbox_reg
$
ymin
+
30000
largeur
=
bbox_reg
$
xmax
-
bbox_reg
$
xmin
+
30000
x_mil
=
bbox_reg
$
xmin
+
largeur
/
2
y_min
=
bbox_reg
$
ymin
-
15000
y_max
=
bbox_reg
$
ymax
+
15000
x_min
=
ifelse
(
largeur
>=
hauteur
,
bbox_reg
$
xmin
-
15000
,
x_mil
-
hauteur
/
2
)
x_max
=
ifelse
(
largeur
>=
hauteur
,
bbox_reg
$
xmax
+
15000
,
x_mil
+
hauteur
/
2
)
}
else
{
y_min
=
bbox_reg
$
ymin
y_max
=
bbox_reg
$
ymax
x_min
=
bbox_reg
$
xmin
x_max
=
bbox_reg
$
xmax
}
p
<-
ggplot2
::
ggplot
()
+
ggplot2
::
geom_sf
(
data
=
fond_carte
$
epci
,
fill
=
"light grey"
,
color
=
"white"
,
size
=
.1
)
+
ggplot2
::
geom_sf
(
data
=
fond_carte
$
reg_ombre
,
fill
=
"dark grey"
,
color
=
"light grey"
)
+
ggplot2
::
geom_sf
(
data
=
fond_carte
$
regions
%>%
filter
(
REG
==
code_region
),
fill
=
"grey"
,
color
=
"white"
,
size
=
.2
)
+
ggplot2
::
geom_sf
(
data
=
data_prep
%>%
dplyr
::
filter
(
epci_reg
),
color
=
"white"
,
size
=
.1
,
fill
=
"#B8B8B8"
)
+
ggplot2
::
geom_sf
(
data
=
data_prep
%>%
dplyr
::
filter
(
epci_reg
,
indicateur_positif
),
color
=
"white"
,
size
=
.1
,
fill
=
"#fff5f1"
)
+
ggplot2
::
geom_sf
(
data
=
fond_carte
$
departements
,
fill
=
NA
,
color
=
"white"
,
size
=
.2
)
+
ggplot2
::
stat_sf_coordinates
(
data
=
data_prep
%>%
dplyr
::
filter
(
epci_reg
,
indicateur_positif
),
aes
(
size
=
Valeur
),
shape
=
21
,
color
=
"white"
,
fill
=
"#000091"
)
+
ggplot2
::
coord_sf
(
xlim
=
c
(
x_min
,
x_max
),
ylim
=
c
(
y_min
,
y_max
),
expand
=
FALSE
,
crs
=
sf
::
st_crs
(
fond_carte
$
epci
),
datum
=
NA
)
+
ggplot2
::
scale_size
(
range
=
c
(
5
/
length
(
indic
),
20
/
length
(
indic
)))
+
ggspatial
::
annotation_north_arrow
(
location
=
"br"
,
style
=
ggspatial
::
north_arrow_fancy_orienteering
)
+
ggspatial
::
annotation_scale
()
+
gouvdown
::
theme_gouv_map
(
base_size
=
12
,
strip_text_size
=
12
,
plot_title_size
=
20
,
subtitle_size
=
16
)
+
ggplot2
::
theme
(
panel.background
=
ggplot2
::
element_rect
(
fill
=
"light blue"
),
plot.background
=
ggplot2
::
element_rect
(
fill
=
"#ffffff"
,
color
=
"#ffffff"
),
legend.position
=
"bottom"
,
legend.title
=
ggplot2
::
element_blank
(),
plot.caption.position
=
"plot"
)
+
ggplot2
::
labs
(
fill
=
titre_legende
,
caption
=
bas_de_page
,
title
=
titre
,
x
=
NULL
,
y
=
NULL
)
if
(
length
(
indic
)
>
1
)
{
p
<-
p
+
facet_wrap
(
~
Indicateur
,
ncol
=
3
)
}
return
(
p
)
}
This diff is collapsed.
Click to expand it.
man/creer_carte_volume.Rd
0 → 100644
+
37
−
0
View file @
ae8b7c8f
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/creer_carte.R
\name{creer_carte_volume}
\alias{creer_carte_volume}
\title{Création de la carte en volume sur les indicateurs de commercialisation de logements neufs}
\usage{
creer_carte_volume(
data = indic_ecln,
code_region = params$reg,
indicateurs = c("Encours", "Mises en vente", "Ventes"),
type_logement = "Appartements",
titre = "",
titre_legende = "",
bas_de_page = ""
)
}
\arguments{
\item{data}{Le dataframe.}
\item{code_region}{Le code de la région.}
\item{indicateurs}{Nom de l'indicateur.}
\item{type_logement}{Appartements ou Maisons.}
\item{titre}{Le titre du graphique.}
\item{titre_legende}{Le titre de la légende.}
\item{bas_de_page}{Le bas de page du graphique.}
}
\value{
une carte en ggplot2
}
\description{
Création de la carte en volume sur les indicateurs de commercialisation de logements neufs
}
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