-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
742 lines (498 loc) · 14.4 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
---
title: "Créer des cartes reproductibles avec mapsf"
author: "Timothée Giraud - UMS RIATE (CNRS, Université de Paris)"
date: "Les lundis de l'Ined - 2021/11/08"
output:
rmdformats::downcute:
highlight: kate
lightbox: TRUE
gallery: FALSE
self_contained: yes
css: libs/style.css
bibliography: references.bib
---
```{r setup, include=FALSE, cache=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
cache=TRUE,
fig.width = 8,
out.width="80%",
fig.align="center"
)
```
####
# La recherche reproductible
### Au coeur de la méthode scientifique
* Les sciences se reposent sur le principe de reproductibilité.
* La reproductibilité est un élément permettant d’évaluer la validité des résultats.
####
### Le spectre de la reproductibilité
```{r, echo = FALSE, fig.cap="@peng2011reproducible"}
knitr::include_graphics("img/peng-spectrum.jpg")
```
Accompagner les publications scientifiques des jeux de données et codes sources pour permettre aux collègues de reproduire les résultats.
####
# La cartographie reproductible
```{r, echo = FALSE, out.width="50%"}
knitr::include_graphics("img/maparticle.jpg")
```
Les cartes, comme les autres productions graphiques ou statistiques sont des éléments à parts entières des études scientifiques.
####
```{r, echo = FALSE}
knitr::include_graphics("img/chain1.png")
```
La plupart des cartes produites dans un contexte académique sont issues de processus complexes.
Elles sont souvent produites en utilisant une grande variété de logiciels et de formats.
####
```{r, echo = FALSE}
knitr::include_graphics("img/chain2.png")
```
Cette variété de formats et de logiciels rend difficile la reproduction des cartes.
####
```{r, echo = FALSE, fig.cap="@giraudlambert"}
knitr::include_graphics("img/giraudlambert.png", dpi=96)
```
####
```{r, echo = FALSE, out.width="1000px"}
knitr::include_graphics("img/chain4.png")
```
Simplifier les chaines de traitement pour couvrir les différentes étapes de la construction cartographique.
####
# R et son écosystème spatial
```{r, echo = FALSE, out.width="25%"}
knitr::include_graphics("img/Rlogo.png")
```
* R est un langage et un environnement permettant de réaliser des traitements statistiques et de représentations graphiques.
* R est un logiciel libre sous license GNU General Public License.
* R est multiplateforme (GNU/Linux, Windows, OS X…).
### Autour de R
* Un large ecosystème de *packages* créés par les contributeurs.
* RStudio, un environnement de développement intégré.
* Une solution de *literate programming* basée sur le langage Markdown.
* Des logiciels de gestion de version (git).
####
### `sf`, pierre angulaire de l'écosystème spatial de R
```{r, echo = FALSE, fig.cap="@pebesma"}
knitr::include_graphics("img/sf_deps.png")
```
####
### `sf`, les fonctionnalités d'un SIG
* Import / Export de données spatiales (vectorielles)
* Affichage
* Gestion des systèmes de coordonnées (les projections)
* Sélections spatiales (*intersects*, *within*, *contains*... )
* Opérations sur les géométries (zone tampon, centroïdes, agrégations, intersections, découpages...)
* Mesures (longueurs, distances, surfaces)
Mais les fonctionnalités cartographiques de `sf` sont limitées.
####
# Le package `mapsf`
```{r, echo = FALSE, out.width="100%", fig.cap="Chaîne de traitement typique"}
knitr::include_graphics("img/workflow.png")
```
####
## `mf_map()`
[`mf_map()`](https://riatelab.github.io/mapsf/reference/mf_map.html) est la fonction principale du package.
```r
mf_map(x = objet_sf,
var = "variable",
type = "type de représentation",
...)
```
```{r, echo = FALSE, out.width="100%", fig.cap="?mapsf"}
knitr::include_graphics("img/help.png")
```
####
## 9 types de carte
Vignette : [Get started](https://riatelab.github.io/mapsf/articles/mapsf.html#symbology)
```{r, echo = FALSE, out.width="657px"}
knitr::include_graphics("img/type.png")
```
####
## Habillage
```{r, echo = FALSE, out.width="80%"}
knitr::include_graphics("img/deco2.svg")
```
####
####
## Exemple
* Affichage du fond de carte :
<div class="row">
<div class="col-md-7" markdown="1">
```{r, results='hide', message = FALSE, echo = FALSE}
library(mapsf)
```
```{r ax, eval=FALSE}
mtq <- mf_get_mtq()
# Plot the base map
mf_map(x = mtq)
```
</div>
<div class="col-md-5" markdown="1">
```{r ax, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE, cache = TRUE}
```
</div>
</div>
* Affichage d'une carte choroplèthe avec les paramètres par défaut :
<div class="row">
<div class="col-md-7" markdown="1">
```{r a, eval=FALSE, highlight.output=c(1, 3)}
mtq <- mf_get_mtq()
# Plot a choropleth map
mf_map(x = mtq, var = "MED", type = "choro")
```
</div>
<div class="col-md-5" markdown="1">
```{r a, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE}
```
</div>
</div>
* Personnalisation des paramètres de la représentation
<div class="row">
<div class="col-md-7" markdown="1">
```{r b, eval=FALSE}
mtq <- mf_get_mtq()
# Plot a choropleth map
mf_map(x = mtq, var = "MED", type = "choro",
pal = "Dark Mint",
breaks = "quantile",
nbreaks = 6,
leg_title = "Median Income\n(euros)",
leg_val_rnd = -2,
leg_pos = "topright")
```
</div>
<div class="col-md-5" markdown="1">
```{r b, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE}
```
</div>
</div>
* Ajout d'éléments d'habillage
<div class="row">
<div class="col-md-7" markdown="1">
```{r c, eval=FALSE}
mtq <- mf_get_mtq()
# Plot a choropleth map
mf_map(x = mtq, var = "MED", type = "choro",
pal = "Dark Mint",
breaks = "quantile",
nbreaks = 6,
leg_title = "Median Income\n(euros)",
leg_val_rnd = -2,
leg_pos = "topright")
# Plot a layout elements
mf_title("Wealth in Martinique, 2015")
mf_credits("T. Giraud\nSources: INSEE & IGN, 2018")
mf_scale(size = 5)
mf_arrow('topleft')
```
</div>
<div class="col-md-5" markdown="1">
```{r c, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE}
```
</div>
</div>
* Utilisation d'un thème
<div class="row">
<div class="col-md-7" markdown="1">
```{r d, eval=FALSE}
mtq <- mf_get_mtq()
# Start a map using a theme
mf_init(x = mtq, theme = "dark")
# Plot a choropleth map
mf_map(x = mtq, var = "MED", type = "choro",
pal = "Dark Mint",
breaks = "quantile",
nbreaks = 6,
leg_title = "Median Income\n(euros)",
leg_val_rnd = -2,
leg_pos = "topright",
add = TRUE)
# Plot a layout elements
mf_title("Wealth in Martinique, 2015")
mf_credits("T. Giraud\nSources: INSEE & IGN, 2018")
mf_scale(size = 5)
mf_arrow('topleft')
```
</div>
<div class="col-md-5" markdown="1">
```{r d, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE}
```
</div>
</div>
* Ajout d'un ombrage
<div class="row">
<div class="col-md-7" markdown="1">
```{r e, eval=FALSE}
mtq <- mf_get_mtq()
# Start a map using a theme
mf_init(x = mtq, theme = "dark")
# Plot a shadow
mf_shadow(mtq, col = "grey10", add = TRUE)
# Plot a choropleth map
mf_map(x = mtq, var = "MED", type = "choro",
pal = "Dark Mint",
breaks = "quantile",
nbreaks = 6,
leg_title = "Median Income\n(euros)",
leg_val_rnd = -2,
leg_pos = "topright",
add = TRUE)
# Plot a layout elements
mf_title("Wealth in Martinique, 2015")
mf_credits("T. Giraud\nSources: INSEE & IGN, 2018")
mf_scale(size = 5)
mf_arrow('topleft')
```
</div>
<div class="col-md-5" markdown="1">
```{r e, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE}
```
</div>
</div>
* Ajout d'un carton de localisation
<div class="row">
<div class="col-md-7" markdown="1">
```{r f, eval=FALSE}
mtq <- mf_get_mtq()
# Start a map using a theme
mf_init(x = mtq, theme = "dark")
# Plot a shadow
mf_shadow(mtq, col = "grey10", add = TRUE)
# Plot a choropleth map
mf_map(x = mtq, var = "MED", type = "choro",
pal = "Dark Mint",
breaks = "quantile",
nbreaks = 6,
leg_title = "Median Income\n(euros)",
leg_val_rnd = -2,
leg_pos = "topright",
add = TRUE)
# Add an inset world map
mf_inset_on(x = "worldmap", pos = "right")
mf_worldmap(mtq, col = "#0E3F5C")
mf_inset_off()
# Plot a layout elements
mf_title("Wealth in Martinique, 2015")
mf_credits("T. Giraud\nSources: INSEE & IGN, 2018")
mf_scale(size = 5)
mf_arrow('topleft')
```
</div>
<div class="col-md-5" markdown="1">
```{r f, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE}
```
</div>
</div>
* Extension des marges de la figure sur la droite
<div class="row">
<div class="col-md-7" markdown="1">
```{r g, eval=FALSE}
mtq <- mf_get_mtq()
# Start a map using a theme and extra margins
mf_init(x = mtq, theme = "dark",
expandBB = c(0,0,0,.3))
# Plot a shadow
mf_shadow(mtq, col = "grey10", add = TRUE)
# Plot a choropleth map
mf_map(x = mtq, var = "MED", type = "choro",
pal = "Dark Mint",
breaks = "quantile",
nbreaks = 6,
leg_title = "Median Income\n(euros)",
leg_val_rnd = -2,
leg_pos = "topright",
add = TRUE)
# Add an inset world map
mf_inset_on(x = "worldmap", pos = "right")
mf_worldmap(mtq, col = "#0E3F5C")
mf_inset_off()
# Plot a layout elements
mf_title("Wealth in Martinique, 2015")
mf_credits("T. Giraud\nSources: INSEE & IGN, 2018")
mf_scale(size = 5)
mf_arrow('topleft')
```
</div>
<div class="col-md-5" markdown="1">
```{r g, message = FALSE, results='hide', fig.width = 5, fig.height=5, eval=TRUE, echo=FALSE}
```
</div>
</div>
####
## Création de cartons
Vignette : [How to Create Inset Maps](https://riatelab.github.io/mapsf/articles/web_only/how_to_create_inset_maps.html)
```{r set, echo = FALSE, cache=FALSE}
mf_theme("default", mar = c(0,0,0,0), bg = "white")
```
* Avec un objet géographique
<div class="row">
<div class="col-md-5" markdown="1">
```{r carton1, eval = FALSE}
mf_map(mtq)
mf_inset_on(x = mtq[1, ],
cex = .3)
mf_map(mtq[1, ])
mf_inset_off()
```
<br><br><br><br><br><br><br><br>
</div>
<div class="col-md-5" markdown="1">
```{r carton1, eval = TRUE, echo = FALSE, fig.width= 5, fig.height = 6, message = FALSE, results='hide'}
```
</div>
</div>
* Avec une carte de localisation
<div class="row">
<div class="col-md-5" markdown="1">
```{r carton2, eval = FALSE}
mf_map(mtq)
mf_inset_on(x = "worldmap",
pos = "bottomleft")
mf_worldmap(x = mtq)
mf_inset_off()
```
<br><br><br><br><br><br><br><br>
</div>
<div class="col-md-5" markdown="1">
```{r carton2, eval = TRUE, echo = FALSE, fig.width= 5, fig.height = 6, message = FALSE, results='hide'}
```
</div>
</div>
* Encart non cartographiques
```{r, echo = FALSE, out.width="394px"}
knitr::include_graphics("img/insethist.png")
```
####
## Thèmes
Vignette : [How to Use Themes](https://riatelab.github.io/mapsf/articles/web_only/how_to_use_themes.html)
```{r, message = FALSE, results='hide', echo = FALSE, fig.height=8, fig.width = 7}
par(mfrow = c(3,3))
mf_theme("default")
mf_map(mtq)
mf_title("default")
mf_theme("jsk")
mf_map(mtq)
mf_title("jsk")
mf_theme("green")
mf_map(mtq)
mf_title("green")
mf_theme("darkula")
mf_map(mtq)
mf_title("darkula")
mf_theme("ink")
mf_map(mtq)
mf_title("ink")
mf_theme("candy")
mf_map(mtq)
mf_title("candy")
mf_theme("dark")
mf_map(mtq)
mf_title("dark")
mf_theme("nevermind")
mf_map(mtq)
mf_title("nevermind")
mf_theme(bg = "#aad3df", fg = "#393939", mar = c(0,0,0,0),
tab = TRUE, inner = TRUE, line = 1.3, pos = "center",
cex = 1.1, font = 3)
mf_map(mtq)
mf_title("Custom")
```
####
## Raster
<div class="row">
<div class="col-md-7" markdown="1">
```{r raster1, message = FALSE, results='hide', eval=FALSE, echo=TRUE}
library(maptiles)
mtq <- st_transform(mtq, 3857)
osm <- get_tiles(
mtq,
provider = "Stamen.TerrainBackground",
crop= TRUE,
zoom = 11
)
th <- mf_theme(
x = "default", bg = "#99b3cc",
inner = TRUE, line = 1.5, cex = 1,
pos = "right", mar = c(0,0,0,0)
)
mf_export(x = osm, filename = "img/osm.png",
width = 672, theme = th, res = 150)
mf_raster(osm)
mf_map(mtq, col = NA, add = TRUE)
mf_scale()
mf_title("mf_raster()")
mf_credits(get_credit("Stamen.TerrainBackground"))
dev.off()
```
</div>
<div class="col-md-5" markdown="1">
```{r, echo = FALSE}
knitr::include_graphics("img/osm.png")
```
</div>
</div>
####
## Nouveau
<div class="row">
<div class="col-md-7" markdown="1">
```{r bg, eval=FALSE}
library(mapsf)
mtq <- mf_get_mtq()
mf_init(mtq, theme = "default")
mf_background("img/blackboard.jpg")
mf_map(mtq, lwd = 3, col = NA,
border = "white", add = TRUE)
mf_credits(
txt = "Photo by Noita Digital on Unsplash",
col = "white"
)
mf_title("mf_background()")
```
</div>
<div class="col-md-5" markdown="1">
```{r bg, message = FALSE, results='hide', eval=TRUE, echo=FALSE, fig.width= 5, fig.height = 6}
```
</div></div>
####
## Développement
Un nombre minimal de dépendances solides.
```{r, echo = FALSE, eval = FALSE, results='hide'}
library(deepdep)
dep <- deepdep("mapsf", depth = 6)
png("img/deps.png", width = 600, height = 450)
plot_dependencies(dep, "circular", same_level = TRUE, reverse = TRUE, main = 'toto')
dev.off()
```
<center>
<img src="img/deps.png" width=600px class="center"/>
</center>
- CI/CD avec les [GitHub Actions](https://github.com/riatelab/mapsf/actions)
- Tests avec le package `tinytest`, couverture avec [Codecov](https://app.codecov.io/gh/riatelab/mapsf)
- Utilisation de la convention de nommage des *commits* [conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.3/)
####
# Merci
[Site web du package](https://riatelab.github.io/mapsf/)
<center>
[<img src="img/website.png" width=800px />](https://riatelab.github.io/mapsf/)
</center>
<div class="row">
<div class="col-md-5" markdown="1">
<img src="img/prlogo.png" width=50px /> [rcarto.github.io/ined2021](https://rcarto.github.io/ined2021)
</div>
<div class="col-md-5" markdown="1">
<img src="img/ghlogo.png" width=50px /> [github.com/riatelab/mapsf](https://github.com/riatelab/mapsf)
</div>
</div>
<div class="row">
<div class="col-md-5" markdown="1">
<img src="img/twlogo.png" width=50px /> [\@rgeomatic](http://twitter.com/rgeomatic)
</div>
<div class="col-md-5" markdown="1">
<img src="img/hylogo.png" width=50px /> [rgeomatic.hypotheses.org](https://rgeomatic.hypotheses.org/)
</div>
</div>
## `sessionInfo()`
```{r test, echo=FALSE}
sessionInfo()
```
## References