Newer
Older
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.1.251">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Mapping and spatial analyses in R for One Health studies - 5 Mapping With R</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
div.csl-bib-body { }
div.csl-entry {
clear: both;
}
.hanging div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}
</style>
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./07-basic_statistics.html" rel="next">
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
<link href="./04-raster_data.html" rel="prev">
<script src="site_libs/quarto-html/quarto.js"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "sidebar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "start",
"type": "textbox",
"limit": 20,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit"
}
}</script>
<style>html{ scroll-behavior: smooth; }</style>
<link rel="stylesheet" href="styles.css">
</head>
<body class="nav-sidebar floating">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<div class="container-fluid d-flex justify-content-between">
<h1 class="quarto-secondary-nav-title"><span class="chapter-number">5</span> <span class="chapter-title">Mapping With R</span></h1>
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
<i class="bi bi-chevron-right"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
<div class="pt-lg-2 mt-2 text-left sidebar-header">
<div class="sidebar-title mb-0 py-0">
<a href="./">Mapping and spatial analyses in R for One Health studies</a>
<div class="sidebar-tools-main">
<a href="https://forge.ird.fr/espace-dev/personnels/longour/geohealth/documentation/rspatial-for-onehealth" title="Source Code" class="sidebar-tool px-1"><i class="bi bi-git"></i></a>
</div>
</div>
</div>
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">Preface</a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./01-introduction.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span> <span class="chapter-title">Introduction</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./02-data_acquisition.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span> <span class="chapter-title">Data Acquisition</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./03-vector_data.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span> <span class="chapter-title">Using vector data</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./04-raster_data.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span> <span class="chapter-title">Using raster data</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./05-mapping_with_r.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">5</span> <span class="chapter-title">Mapping With R</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./07-basic_statistics.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span> <span class="chapter-title">Basic statistics for spatial analysis</span></a>
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
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./references.html" class="sidebar-item-text sidebar-link">References</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#types-of-maps" id="toc-types-of-maps" class="nav-link active" data-scroll-target="#types-of-maps"><span class="toc-section-number">5.1</span> Types of maps</a>
<ul>
<li><a href="#create-a-simple-map" id="toc-create-a-simple-map" class="nav-link" data-scroll-target="#create-a-simple-map"><span class="toc-section-number">5.1.1</span> Create a simple map</a></li>
<li><a href="#proportional-symbol-map" id="toc-proportional-symbol-map" class="nav-link" data-scroll-target="#proportional-symbol-map"><span class="toc-section-number">5.1.2</span> Proportional symbol map</a>
<ul class="collapse">
<li><a href="#compare-multiple-map" id="toc-compare-multiple-map" class="nav-link" data-scroll-target="#compare-multiple-map"><span class="toc-section-number">5.1.2.1</span> Compare multiple map</a></li>
</ul></li>
<li><a href="#choropleth-map" id="toc-choropleth-map" class="nav-link" data-scroll-target="#choropleth-map"><span class="toc-section-number">5.1.3</span> Choropleth map</a>
<ul class="collapse">
<li><a href="#discretisation" id="toc-discretisation" class="nav-link" data-scroll-target="#discretisation"><span class="toc-section-number">5.1.3.1</span> Discretisation</a></li>
<li><a href="#palettes" id="toc-palettes" class="nav-link" data-scroll-target="#palettes"><span class="toc-section-number">5.1.3.2</span> Color palettes</a></li>
<li><a href="#for-a-point-layer" id="toc-for-a-point-layer" class="nav-link" data-scroll-target="#for-a-point-layer"><span class="toc-section-number">5.1.3.3</span> For a point layer</a></li>
</ul></li>
<li><a href="#typology-map" id="toc-typology-map" class="nav-link" data-scroll-target="#typology-map"><span class="toc-section-number">5.1.4</span> Typology map</a>
<ul class="collapse">
<li><a href="#ordering-value-in-the-legend" id="toc-ordering-value-in-the-legend" class="nav-link" data-scroll-target="#ordering-value-in-the-legend"><span class="toc-section-number">5.1.4.1</span> Ordering value in the legend</a></li>
<li><a href="#map-of-point" id="toc-map-of-point" class="nav-link" data-scroll-target="#map-of-point"><span class="toc-section-number">5.1.4.2</span> Map of point</a></li>
<li><a href="#map-of-lines" id="toc-map-of-lines" class="nav-link" data-scroll-target="#map-of-lines"><span class="toc-section-number">5.1.4.3</span> Map of lines</a></li>
</ul></li>
<li><a href="#map-of-stocks-and-ratios" id="toc-map-of-stocks-and-ratios" class="nav-link" data-scroll-target="#map-of-stocks-and-ratios"><span class="toc-section-number">5.1.5</span> Map of stocks and ratios</a></li>
<li><a href="#map-of-stocks-and-categories" id="toc-map-of-stocks-and-categories" class="nav-link" data-scroll-target="#map-of-stocks-and-categories"><span class="toc-section-number">5.1.6</span> Map of stocks and categories</a></li>
</ul></li>
<li><a href="#layout" id="toc-layout" class="nav-link" data-scroll-target="#layout"><span class="toc-section-number">5.2</span> Layout</a>
<ul>
<li><a href="#example-data" id="toc-example-data" class="nav-link" data-scroll-target="#example-data"><span class="toc-section-number">5.2.1</span> Example data</a></li>
<li><a href="#themes" id="toc-themes" class="nav-link" data-scroll-target="#themes"><span class="toc-section-number">5.2.2</span> Themes</a>
<ul class="collapse">
<li><a href="#use-a-predefined-theme" id="toc-use-a-predefined-theme" class="nav-link" data-scroll-target="#use-a-predefined-theme"><span class="toc-section-number">5.2.2.1</span> Use a predefined theme</a></li>
<li><a href="#modify-an-existing-theme" id="toc-modify-an-existing-theme" class="nav-link" data-scroll-target="#modify-an-existing-theme"><span class="toc-section-number">5.2.2.2</span> Modify an existing theme</a></li>
<li><a href="#create-a-theme" id="toc-create-a-theme" class="nav-link" data-scroll-target="#create-a-theme"><span class="toc-section-number">5.2.2.3</span> Create a theme</a></li>
</ul></li>
<li><a href="#titles" id="toc-titles" class="nav-link" data-scroll-target="#titles"><span class="toc-section-number">5.2.3</span> Titles</a></li>
<li><a href="#arrow-orientation" id="toc-arrow-orientation" class="nav-link" data-scroll-target="#arrow-orientation"><span class="toc-section-number">5.2.4</span> Arrow orientation</a></li>
<li><a href="#scale" id="toc-scale" class="nav-link" data-scroll-target="#scale"><span class="toc-section-number">5.2.5</span> Scale</a></li>
<li><a href="#credits" id="toc-credits" class="nav-link" data-scroll-target="#credits"><span class="toc-section-number">5.2.6</span> Credits</a></li>
<li><a href="#complete-dressing" id="toc-complete-dressing" class="nav-link" data-scroll-target="#complete-dressing"><span class="toc-section-number">5.2.7</span> Complete dressing</a></li>
<li><a href="#annotations" id="toc-annotations" class="nav-link" data-scroll-target="#annotations"><span class="toc-section-number">5.2.8</span> Annotations</a></li>
<li><a href="#legends" id="toc-legends" class="nav-link" data-scroll-target="#legends"><span class="toc-section-number">5.2.9</span> Legends</a></li>
<li><a href="#labels" id="toc-labels" class="nav-link" data-scroll-target="#labels"><span class="toc-section-number">5.2.10</span> Labels</a></li>
<li><a href="#center-the-map-on-a-region" id="toc-center-the-map-on-a-region" class="nav-link" data-scroll-target="#center-the-map-on-a-region"><span class="toc-section-number">5.2.11</span> Center the map on a region</a></li>
<li><a href="#displaying-several-maps-on-the-same-figure" id="toc-displaying-several-maps-on-the-same-figure" class="nav-link" data-scroll-target="#displaying-several-maps-on-the-same-figure"><span class="toc-section-number">5.2.12</span> Displaying several maps on the same figure</a></li>
<li><a href="#exporting-maps" id="toc-exporting-maps" class="nav-link" data-scroll-target="#exporting-maps"><span class="toc-section-number">5.2.13</span> Exporting maps</a></li>
<li><a href="#adding-an-image-to-a-map" id="toc-adding-an-image-to-a-map" class="nav-link" data-scroll-target="#adding-an-image-to-a-map"><span class="toc-section-number">5.2.14</span> Adding an image to a map</a></li>
<li><a href="#place-an-item-precisely-on-the-map" id="toc-place-an-item-precisely-on-the-map" class="nav-link" data-scroll-target="#place-an-item-precisely-on-the-map"><span class="toc-section-number">5.2.15</span> Place an item precisely on the map</a></li>
<li><a href="#add-shading-to-a-layer" id="toc-add-shading-to-a-layer" class="nav-link" data-scroll-target="#add-shading-to-a-layer"><span class="toc-section-number">5.2.16</span> Add shading to a layer</a></li>
<li><a href="#creating-boxes" id="toc-creating-boxes" class="nav-link" data-scroll-target="#creating-boxes"><span class="toc-section-number">5.2.17</span> Creating Boxes</a></li>
</ul></li>
<li><a href="#d-maps" id="toc-d-maps" class="nav-link" data-scroll-target="#d-maps"><span class="toc-section-number">5.3</span> 3D maps</a>
<ul>
<li><a href="#linemap" id="toc-linemap" class="nav-link" data-scroll-target="#linemap"><span class="toc-section-number">5.3.1</span> linemap</a></li>
<li><a href="#relief-tanaka" id="toc-relief-tanaka" class="nav-link" data-scroll-target="#relief-tanaka"><span class="toc-section-number">5.3.2</span> Relief Tanaka</a></li>
</ul></li>
<li><a href="#cartographic-transformation" id="toc-cartographic-transformation" class="nav-link" data-scroll-target="#cartographic-transformation"><span class="toc-section-number">5.4</span> Cartographic Transformation</a>
<ul>
<li><a href="#dorlings-cartograms" id="toc-dorlings-cartograms" class="nav-link" data-scroll-target="#dorlings-cartograms"><span class="toc-section-number">5.4.1</span> Dorling’s cartograms</a></li>
<li><a href="#non-continuous-cartograms" id="toc-non-continuous-cartograms" class="nav-link" data-scroll-target="#non-continuous-cartograms"><span class="toc-section-number">5.4.2</span> Non-continuous cartograms</a></li>
<li><a href="#continuous-cartograms" id="toc-continuous-cartograms" class="nav-link" data-scroll-target="#continuous-cartograms"><span class="toc-section-number">5.4.3</span> Continuous cartograms</a></li>
<li><a href="#stengths-and-weaknessses-of-cartograms" id="toc-stengths-and-weaknessses-of-cartograms" class="nav-link" data-scroll-target="#stengths-and-weaknessses-of-cartograms"><span class="toc-section-number">5.4.4</span> Stengths and weaknessses of cartograms</a></li>
</ul></li>
</ul>
</nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title d-none d-lg-block"><span class="chapter-number">5</span> <span class="chapter-title">Mapping With R</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<section id="types-of-maps" class="level2" data-number="5.1">
<h2 data-number="5.1" class="anchored" data-anchor-id="types-of-maps"><span class="header-section-number">5.1</span> Types of maps</h2>
<p>The fonction <code>mf_map()</code> is the central function of the package <code>mapsf</code> <span class="citation" data-cites="mapsf">(<a href="references.html#ref-mapsf" role="doc-biblioref">Giraud 2022a</a>)</span>. It makes it possible to carry out most of the usual representations in cartography. These main arguments are:</p>
<ul>
<li><code>x</code>, an sf object ;</li>
<li><code>var</code>, the name of variable to present ;</li>
<li><code>type</code>, the type of presentation.</li>
</ul>
<section id="create-a-simple-map" class="level3" data-number="5.1.1">
<h3 data-number="5.1.1" class="anchored" data-anchor-id="create-a-simple-map"><span class="header-section-number">5.1.1</span> Create a simple map</h3>
<p>The following lines import the spatial information layers located in the <a href="https://www.geopackage.org/">geopackage</a> <strong>cambodia.gpkg</strong> file.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="co">#Import Cambodia country border</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>country <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"country"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="co">#Import provincial administrative border of Cambodia</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>education <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"education"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="co">#Import district administrative border of Cambodia</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>district <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"district"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="co">#Import roads data in Cambodia</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>road <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"road"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="co">#Import health center data in Cambodia</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a>hospital <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"hospital"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(mapsf)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district, <span class="at">border =</span> <span class="st">"white"</span>)</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> country,<span class="at">lwd =</span> <span class="dv">2</span>, <span class="at">col =</span> <span class="cn">NA</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> road, <span class="at">lwd =</span> .<span class="dv">5</span>, <span class="at">col =</span> <span class="st">"ivory4"</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> hospital, <span class="at">pch =</span> <span class="dv">20</span>, <span class="at">cex =</span> <span class="dv">1</span>, <span class="at">col =</span> <span class="st">"#FE9A2E"</span>, <span class="at">add =</span> <span class="cn">TRUE</span>) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/mf_base-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="proportional-symbol-map" class="level3" data-number="5.1.2">
<h3 data-number="5.1.2" class="anchored" data-anchor-id="proportional-symbol-map"><span class="header-section-number">5.1.2</span> Proportional symbol map</h3>
<p>Proportional symbol maps are used to represent inventory variables (absolute quantitative variables, sum and average make sense). The function <code>mf_map(..., type = "prop")</code> proposes this representation.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">#District</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district) </span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Proportional symbol </span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district, </span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"T_POP"</span>,</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> <span class="at">val_max =</span> <span class="dv">700000</span>,</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"prop"</span>,</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a> <span class="at">col =</span> <span class="st">"#148F77"</span>, </span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">"Population 2019"</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="co"># Title</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Distribution of population in provincial level"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/proportional_symbols-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<section id="compare-multiple-map" class="level4" data-number="5.1.2.1">
<h4 data-number="5.1.2.1" class="anchored" data-anchor-id="compare-multiple-map"><span class="header-section-number">5.1.2.1</span> Compare multiple map</h4>
<p>It is possible to fix the dimensions of the largest symbol corresponding to a certain value with the arguments <code>inches</code> and <code>val_max</code>. We can use construct maps with comparable proportional symbols.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">par</span>(<span class="at">mfrow =</span> <span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>)) <span class="co">#Displaying two maps facing each other</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co">#district</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district, <span class="at">border =</span> <span class="st">"grey90"</span>, <span class="at">lwd =</span> .<span class="dv">5</span>) </span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Add male Population</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district, </span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"Male"</span>, </span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"prop"</span>,</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a> <span class="at">col =</span> <span class="st">"#1F618D"</span>,</span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a> <span class="at">inches =</span> <span class="fl">0.2</span>, </span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a> <span class="at">val_max =</span> <span class="dv">300000</span>, </span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">"Male"</span>, </span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_val_cex =</span> <span class="fl">0.5</span>,</span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Male Population by Distict"</span>) <span class="co">#Adding map title</span></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a><span class="co">#district</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district, <span class="at">border =</span> <span class="st">"grey90"</span>, <span class="at">lwd =</span> .<span class="dv">5</span>) </span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a><span class="co"># Add female Population</span></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district, </span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"Female"</span>, </span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"prop"</span>,</span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a> <span class="at">col =</span> <span class="st">"#E74C3C"</span>,</span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a> <span class="at">inches =</span> <span class="fl">0.2</span>, </span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true" tabindex="-1"></a> <span class="at">val_max =</span> <span class="dv">300000</span>, </span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span><span class="st">"Female"</span>, </span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_val_cex =</span> <span class="fl">0.5</span></span>
<span id="cb4-30"><a href="#cb4-30" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb4-31"><a href="#cb4-31" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Female Population by Distict"</span>) <span class="co">#Adding map title</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/proportional_symbols_comp-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>Here we have displayed two maps facing each other, see the point <a href="#afficher-plusieurs-cartes-sur-la-même-figure">Displaying several maps on the same figure</a> for more details.</p>
</section>
</section>
<section id="choropleth-map" class="level3" data-number="5.1.3">
<h3 data-number="5.1.3" class="anchored" data-anchor-id="choropleth-map"><span class="header-section-number">5.1.3</span> Choropleth map</h3>
<p>Choropleth maps are used to represent ratio variables (relative quantitative variables, mean has meaning, sum has no meaning).</p>
<p>For this type of representation, you must first:</p>
<ul>
<li>choose a discretization method to transform a continuous statistical series into classes defined by intervals,</li>
<li>choose a number of classes,</li>
<li>choose a color palette.</li>
</ul>
<p>The function mf_map(…, type = “choro”)makes it possible to create choroplete maps. The arguments nbreaks and breaks are used to parameterize the discretizations, and the function <code>mf_get_breaks()</code> makes it possible to work on the discretizations outside the function <code>mf_map()</code>. Similarly, the argument palis used to fill in a color palette, but several functions can be used to set the palettes apart from the (<code>mf_get_pal</code>…) function.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Population density (inhabitants/km2) using the sf::st_area() function</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>DENS <span class="ot"><-</span> <span class="fl">1e6</span> <span class="sc">*</span> district<span class="sc">$</span>T_POP <span class="sc">/</span> <span class="fu">as.numeric</span>(<span class="fu">st_area</span>(district)) <span class="co">#Calculate population density </span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district,</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"DENS"</span>,</span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"choro"</span>,</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="at">breaks =</span> <span class="st">"quantile"</span>,</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="st">"BuGn"</span>,</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> <span class="dv">1</span>,</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">"Distribution of population</span><span class="sc">\n</span><span class="st">(inhabitants per km2)"</span>, </span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_val_rnd =</span> <span class="dv">0</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Distribution of the population in (2019)"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/choro-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>cases <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"cases"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>) <span class="co"># load cases layer</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>cases <span class="ot">=</span> <span class="fu">subset</span>(cases, Disease <span class="sc">==</span> <span class="st">"W fever"</span>) <span class="co"># subset data to only keep W fever cases</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>population <span class="ot"><-</span> <span class="fu">read.csv</span>(<span class="st">"data_cambodia/khm_admpop_adm2_2016_v2.csv"</span>) <span class="co"># read population data</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>population <span class="ot"><-</span> population[, <span class="fu">c</span>(<span class="st">"ADM2_PCODE"</span>, <span class="st">"T_TL"</span>)] <span class="co"># just select few columns</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>population<span class="sc">$</span>T_TL <span class="ot"><-</span> <span class="fu">as.numeric</span>(<span class="fu">gsub</span>(<span class="st">","</span>,<span class="st">""</span>,population<span class="sc">$</span>T_TL)) <span class="co"># Remove commas (not supposed to be in the dataframe)</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>cases <span class="ot"><-</span> <span class="fu">lengths</span>(<span class="fu">st_intersects</span>(district, cases)) <span class="co"># count points in polygons</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a>district <span class="ot"><-</span> <span class="fu">merge</span>(district,</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> population,</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> <span class="at">by =</span> <span class="st">"ADM2_PCODE"</span>) <span class="co"># merge shape with population data</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>incidence <span class="ot"><-</span> district<span class="sc">$</span>cases <span class="sc">/</span> district<span class="sc">$</span>T_TL <span class="sc">*</span> <span class="dv">100000</span> <span class="co"># calculate incidence</span></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district,</span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"incidence"</span>,</span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"choro"</span>,</span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">"Incidence (per 100 000)"</span>)</span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_layout</span>(<span class="at">title =</span> <span class="st">"Incidence of W Fever in Cambodia"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
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
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/choro-incidence-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<section id="discretisation" class="level4" data-number="5.1.3.1">
<h4 data-number="5.1.3.1" class="anchored" data-anchor-id="discretisation"><span class="header-section-number">5.1.3.1</span> Discretisation</h4>
<p>The fonction <code>mf_get_breaks()</code> provides the methods of discretization of classic variables: quantiles, average/standard deviation, equal amplitudes, nested averages, Fisher-Jenks, geometric, etc.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>education<span class="sc">$</span>enrol_g_pct <span class="ot">=</span> <span class="dv">100</span> <span class="sc">*</span> education<span class="sc">$</span>enrol_girl<span class="sc">/</span>education<span class="sc">$</span>t_enrol <span class="co">#Calculate percentage of enrolled girl student</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>d1 <span class="ot">=</span> <span class="fu">mf_get_breaks</span>(education<span class="sc">$</span>enrol_g_pct, <span class="at">nbreaks =</span> <span class="dv">6</span>, <span class="at">breaks =</span> <span class="st">"equal"</span>, <span class="at">freq =</span> <span class="cn">TRUE</span>)</span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>d2 <span class="ot">=</span> <span class="fu">mf_get_breaks</span>(education<span class="sc">$</span>enrol_g_pct, <span class="at">nbreaks =</span> <span class="dv">6</span>, <span class="at">breaks =</span> <span class="st">"quantile"</span>)</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>d3 <span class="ot">=</span> <span class="fu">mf_get_breaks</span>(education<span class="sc">$</span>enrol_g_pct, <span class="at">nbreaks =</span> <span class="dv">6</span>, <span class="at">breaks =</span> <span class="st">"geom"</span>)</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>d4 <span class="ot">=</span> <span class="fu">mf_get_breaks</span>(education<span class="sc">$</span>enrol_g_pct, <span class="at">breaks =</span> <span class="st">"msd"</span>, <span class="at">central =</span> <span class="cn">FALSE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/discr3-1.png" class="img-fluid" width="768"></p>
</div>
</div>
</section>
<section id="palettes" class="level4" data-number="5.1.3.2">
<h4 data-number="5.1.3.2" class="anchored" data-anchor-id="palettes"><span class="header-section-number">5.1.3.2</span> Color palettes</h4>
<p>The argument <code>pal</code> de <code>mf_map()</code> is dedicated to choosing a color palette. The palettes provided by the function <code>hcl.colors()</code> can be used directly.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> education, <span class="at">var =</span> <span class="st">"enrol_g_pct"</span>, <span class="at">type =</span> <span class="st">"choro"</span>,</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="at">breaks =</span> d3, <span class="at">pal =</span> <span class="st">"Reds 3"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/pal1-1.png" class="img-fluid" width="576"></p>
</div>
</div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="img/swatch-plot-1.svg" class="img-fluid figure-img" width="600"></p>
</figure>
</div>
<p>The fonction <code>mf_get_pal()</code> allows you to build a color palette. This function is especially useful for creating balanced asymmetrical diverging palettes.</p>
<div class="cell" data-nm="true">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>mypal <span class="ot"><-</span> <span class="fu">mf_get_pal</span>(<span class="at">n =</span> <span class="fu">c</span>(<span class="dv">4</span>,<span class="dv">6</span>), <span class="at">palette =</span> <span class="fu">c</span>(<span class="st">"Burg"</span>, <span class="st">"Teal"</span>))</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="fu">image</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>, <span class="dv">1</span>, <span class="fu">as.matrix</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>), <span class="at">col=</span>mypal, <span class="at">xlab =</span> <span class="st">""</span>, <span class="at">ylab =</span> <span class="st">""</span>, <span class="at">xaxt =</span> <span class="st">"n"</span>,</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="at">yaxt =</span> <span class="st">"n"</span>,<span class="at">bty =</span> <span class="st">"n"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/pal2-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="for-a-point-layer" class="level4" data-number="5.1.3.3">
<h4 data-number="5.1.3.3" class="anchored" data-anchor-id="for-a-point-layer"><span class="header-section-number">5.1.3.3</span> For a point layer</h4>
<p>It is possible to use this mode of presentation in specific implementation also.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>dist_c <span class="ot"><-</span> <span class="fu">st_centroid</span>(district)</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> dist_c,</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"DENS"</span>,</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"choro"</span>,</span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> <span class="at">breaks =</span> <span class="st">"quantile"</span>,</span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> <span class="at">nbreaks =</span> <span class="dv">5</span>,</span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="st">"PuRd"</span>,</span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a> <span class="at">pch =</span> <span class="dv">23</span>,</span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a> <span class="at">cex =</span> <span class="fl">1.5</span>,</span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a> <span class="at">border =</span> <span class="st">"white"</span>,</span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> .<span class="dv">7</span>,</span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_pos =</span> <span class="st">"topleft"</span>,</span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">"Distribution of population</span><span class="sc">\n</span><span class="st">(inhabitants per km2)"</span>, </span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_val_rnd =</span> <span class="dv">0</span>, </span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a> <span class="at">add =</span> <span class="cn">TRUE</span></span>
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Distribution of population in (2019)"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/choropt-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
</section>
<section id="typology-map" class="level3" data-number="5.1.4">
<h3 data-number="5.1.4" class="anchored" data-anchor-id="typology-map"><span class="header-section-number">5.1.4</span> Typology map</h3>
<p>Typology maps are used to represent qualitative variables. The function <code>mf_map(..., type = "typo")</code> proposes this representation.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district,</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="at">var=</span><span class="st">"Status"</span>,</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"typo"</span>,</span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="fu">c</span>(<span class="st">'#E8F9FD'</span>,<span class="st">'#FF7396'</span>,<span class="st">'#E4BAD4'</span>,<span class="st">'#FFE3FE'</span>),</span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> .<span class="dv">7</span>,</span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">""</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Administrative status by size of area"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/typo_simple-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<section id="ordering-value-in-the-legend" class="level4" data-number="5.1.4.1">
<h4 data-number="5.1.4.1" class="anchored" data-anchor-id="ordering-value-in-the-legend"><span class="header-section-number">5.1.4.1</span> Ordering value in the legend</h4>
<p>The argument <code>val_order</code> is used to order the categories in the</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district,</span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="at">var=</span><span class="st">"Status"</span>,</span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"typo"</span>,</span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="fu">c</span>(<span class="st">'#E8F9FD'</span>,<span class="st">'#FF7396'</span>,<span class="st">'#E4BAD4'</span>,<span class="st">'#FFE3FE'</span>),</span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a> <span class="at">val_order =</span> <span class="fu">c</span>(<span class="st">"1st largest district"</span>, <span class="st">"2nd largest district"</span>, <span class="st">"3rd largest district"</span>,<span class="st">"<4500km2"</span>),</span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> .<span class="dv">7</span>,</span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">""</span></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Administrative status by size of area"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/typo_order-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="map-of-point" class="level4" data-number="5.1.4.2">
<h4 data-number="5.1.4.2" class="anchored" data-anchor-id="map-of-point"><span class="header-section-number">5.1.4.2</span> Map of point</h4>
<p>When the implantation of the layer is punctual, symbols are used to carry the colors of the typology.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co">#extract centroid point of the district</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>dist_ctr <span class="ot"><-</span> <span class="fu">st_centroid</span>(district[district<span class="sc">$</span>Status <span class="sc">!=</span> <span class="st">"<4500km2"</span>, ])</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> dist_ctr,</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"Status"</span>,</span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"typo"</span>,</span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a> <span class="at">cex =</span> <span class="dv">2</span>,</span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a> <span class="at">pch =</span> <span class="dv">22</span>,</span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="fu">c</span>(<span class="st">'#FF7396'</span>,<span class="st">'#E4BAD4'</span>,<span class="st">'#FFE3FE'</span>),</span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">""</span>,</span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_pos =</span> <span class="st">"bottomright"</span>,</span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true" tabindex="-1"></a> <span class="at">add =</span> <span class="cn">TRUE</span></span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Administrative status by size of area"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/typo_point-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="map-of-lines" class="level4" data-number="5.1.4.3">
<h4 data-number="5.1.4.3" class="anchored" data-anchor-id="map-of-lines"><span class="header-section-number">5.1.4.3</span> Map of lines</h4>
<div class="cell">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="co">#Selection of roads that intersect the city of Siem Reap</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>pp <span class="ot"><-</span> district[district<span class="sc">$</span>ADM1_EN <span class="sc">==</span> <span class="st">"Phnom Penh"</span>, ]</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>road_pp <span class="ot"><-</span> road[<span class="fu">st_intersects</span>(<span class="at">x =</span> road, <span class="at">y =</span> pp, <span class="at">sparse =</span> <span class="cn">FALSE</span>), ]</span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(pp)</span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> road_pp,</span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"fclass"</span>,</span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"typo"</span>,</span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> <span class="fl">1.2</span>,</span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="fu">mf_get_pal</span>(<span class="at">n =</span> <span class="dv">6</span>, <span class="st">"Tropic"</span>),</span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="st">"Types of road"</span>,</span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_pos =</span> <span class="st">"topright"</span>,</span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_frame =</span> T,</span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a> <span class="at">add =</span> <span class="cn">TRUE</span></span>
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Administrative status"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
</section>
<section id="map-of-stocks-and-ratios" class="level3" data-number="5.1.5">
<h3 data-number="5.1.5" class="anchored" data-anchor-id="map-of-stocks-and-ratios"><span class="header-section-number">5.1.5</span> Map of stocks and ratios</h3>
<p>The function <code>mf_map(..., var = c("var1", "var2"), type = "prop_choro")</code> represents proportional symbols whose areas are proportional to the values of one variable and whose color is based on the discretization of a second variable. The function uses the arguments of the functions <code>mf_map(..., type = "prop")</code> and <code>mf_map(..., type = "choro")</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district)</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district,</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="fu">c</span>(<span class="st">"T_POP"</span>, <span class="st">"DENS"</span>),</span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> <span class="at">val_max =</span> <span class="dv">500000</span>,</span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"prop_choro"</span>,</span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a> <span class="at">border =</span> <span class="st">"grey60"</span>,</span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> <span class="fl">0.5</span>,</span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_pos =</span> <span class="fu">c</span>(<span class="st">"bottomright"</span>, <span class="st">"bottomleft"</span>),</span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="fu">c</span>(<span class="st">"Population"</span>, <span class="st">"Density of</span><span class="sc">\n</span><span class="st"> population</span><span class="sc">\n</span><span class="st">(inhabitants per km2)"</span>),</span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true" tabindex="-1"></a> <span class="at">breaks =</span> <span class="st">"q6"</span>,</span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="st">"Blues 3"</span>,</span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_val_rnd =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">1</span>))</span>
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/choroprop-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="map-of-stocks-and-categories" class="level3" data-number="5.1.6">
<h3 data-number="5.1.6" class="anchored" data-anchor-id="map-of-stocks-and-categories"><span class="header-section-number">5.1.6</span> Map of stocks and categories</h3>
<p>The function <code>mf_map(..., var = c("var1", "var2"), type = "prop_typo")</code> represents proportional symbols whose areas are proportional to the values of one variable and whose color is based on the discretization of a second variable. The function uses the arguments of the <code>mf_map(..., type = "prop")</code> and function <code>mf_map(..., type = "typo")</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district)</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> district,</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="fu">c</span>(<span class="st">"Area.Km2."</span>, <span class="st">"Status"</span>),</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"prop_typo"</span>,</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="fu">c</span>(<span class="st">'#E8F9FD'</span>,<span class="st">'#FF7396'</span>,<span class="st">'#E4BAD4'</span>,<span class="st">'#FFE3FE'</span>),</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a> <span class="at">val_order =</span> <span class="fu">c</span>(<span class="st">"<4500km2"</span>,<span class="st">"1st largest district"</span>, <span class="st">"2nd largest district"</span>, <span class="st">"3rd largest district"</span>),</span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_pos =</span> <span class="fu">c</span>(<span class="st">"bottomleft"</span>,<span class="st">"topleft"</span>),</span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a> <span class="at">leg_title =</span> <span class="fu">c</span>(<span class="st">"Population</span><span class="sc">\n</span><span class="st">(2019)"</span>,</span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a> <span class="st">"Statut administratif"</span>),</span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/typoprop-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
</section>
<section id="layout" class="level2" data-number="5.2">
<h2 data-number="5.2" class="anchored" data-anchor-id="layout"><span class="header-section-number">5.2</span> Layout</h2>
<p>To be finalized, a thematic map must contain certain additional elements such as: title, author, source, scale, orientation…</p>
<section id="example-data" class="level3" data-number="5.2.1">
<h3 data-number="5.2.1" class="anchored" data-anchor-id="example-data"><span class="header-section-number">5.2.1</span> Example data</h3>
<p>The following lines import the spatial information layers located in the <a href="https://www.geopackage.org/">geopackage</a> <strong>cambodia.gpkg</strong> file.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>country <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"country"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>) <span class="co">#Import Cambodia country border</span></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>education <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"education"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>) <span class="co">#Import provincial administrative border of Cambodia</span></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>district <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"district"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>) <span class="co">#Import district administrative border of Cambodia</span></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>road <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"road"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>) <span class="co">#Import roads data in Cambodia</span></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a>hospital <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"hospital"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>) <span class="co">#Import hospital data in Cambodia</span></span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a>cases <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/cambodia.gpkg"</span>, <span class="at">layer =</span> <span class="st">"cases"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>) <span class="co">#Import example data of fever_cases in Cambodia</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="themes" class="level3" data-number="5.2.2">
<h3 data-number="5.2.2" class="anchored" data-anchor-id="themes"><span class="header-section-number">5.2.2</span> Themes</h3>
<p>The function <code>mf_theme()</code> defines a cartographic theme. Using a theme allows you to define several graphic parameters which are then applied to the maps created with <code>mapsf</code>. These parameters are: the map margins, the main color, the background color, the position and the aspect of the title. A theme can also be defined with the <code>mf_init()</code> and function <code>mf_export()</code>.</p>
<section id="use-a-predefined-theme" class="level4" data-number="5.2.2.1">
<h4 data-number="5.2.2.1" class="anchored" data-anchor-id="use-a-predefined-theme"><span class="header-section-number">5.2.2.1</span> Use a predefined theme</h4>
<p>A series of predefined themes are available by default (see <code>?mf_theme</code>).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(mapsf)</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="co"># use of a background color for the figure, to see the use of margin</span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a>opar <span class="ot"><-</span> <span class="fu">par</span>(<span class="at">mfrow =</span> <span class="fu">c</span>(<span class="dv">2</span>,<span class="dv">2</span>))</span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Using a predefined theme</span></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"default"</span>)</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Theme : 'default'"</span>)</span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"darkula"</span>)</span>
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Theme : 'darkula'"</span>)</span>
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"candy"</span>)</span>
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb18-15"><a href="#cb18-15" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Theme : 'candy'"</span>)</span>
<span id="cb18-16"><a href="#cb18-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb18-17"><a href="#cb18-17" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"nevermind"</span>)</span>
<span id="cb18-18"><a href="#cb18-18" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb18-19"><a href="#cb18-19" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Theme : 'nevermind'"</span>)</span>
<span id="cb18-20"><a href="#cb18-20" aria-hidden="true" tabindex="-1"></a><span class="fu">par</span>(opar)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/them1-1.png" class="img-fluid" width="768"></p>
</div>
</div>
</section>
<section id="modify-an-existing-theme" class="level4" data-number="5.2.2.2">
<h4 data-number="5.2.2.2" class="anchored" data-anchor-id="modify-an-existing-theme"><span class="header-section-number">5.2.2.2</span> Modify an existing theme</h4>
<p>It is possible to modify an existing theme. In this example, we are using the “default” theme and modifying a few settings.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(mapsf)</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>opar <span class="ot"><-</span> <span class="fu">par</span>(<span class="at">mfrow =</span> <span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>))</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"default"</span>)</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"default"</span>)</span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"default"</span>, <span class="at">tab =</span> <span class="cn">FALSE</span>, <span class="at">font =</span> <span class="dv">4</span>, <span class="at">bg =</span> <span class="st">"grey60"</span>, <span class="at">pos =</span> <span class="st">"center"</span>)</span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"modified default"</span>)</span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a><span class="fu">par</span>(opar)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/theme2-1.png" class="img-fluid" width="768"></p>
</div>
</div>
</section>
<section id="create-a-theme" class="level4" data-number="5.2.2.3">
<h4 data-number="5.2.2.3" class="anchored" data-anchor-id="create-a-theme"><span class="header-section-number">5.2.2.3</span> Create a theme</h4>
<p>It is also possible to create a theme.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> <span class="at">bg =</span> <span class="st">"lightblue"</span>, <span class="co"># background color</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a> <span class="at">fg =</span> <span class="st">"tomato1"</span>, <span class="co"># main color</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> <span class="at">mar =</span> <span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">0</span>,<span class="fl">1.5</span>,<span class="dv">0</span>), <span class="co"># margin</span></span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a> <span class="at">tab =</span> <span class="cn">FALSE</span>, <span class="co"># "tab" style for the title</span></span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a> <span class="at">inner =</span> <span class="cn">FALSE</span>, <span class="co"># title inside or outside of map area</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a> <span class="at">line =</span> <span class="fl">1.5</span>, <span class="co"># space dedicated to title</span></span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a> <span class="at">pos =</span> <span class="st">"center"</span>, <span class="co"># heading position</span></span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a> <span class="at">cex =</span> <span class="fl">1.5</span>, <span class="co"># title size</span></span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a> <span class="at">font =</span> <span class="dv">2</span> <span class="co"># font types for title</span></span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"New theme"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
</section>
<section id="titles" class="level3" data-number="5.2.3">
<h3 data-number="5.2.3" class="anchored" data-anchor-id="titles"><span class="header-section-number">5.2.3</span> Titles</h3>
<p>The function <code>mf_title()</code> adds a title to a map.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"default"</span>)</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Map title"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>It is possible to customize the appearance of the title</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="at">txt =</span> <span class="st">"Map title"</span>, </span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a> <span class="at">pos =</span> <span class="st">"center"</span>, </span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a> <span class="at">tab =</span> <span class="cn">FALSE</span>, </span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a> <span class="at">bg =</span> <span class="st">"tomato3"</span>, </span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a> <span class="at">fg =</span> <span class="st">"lightblue"</span>, </span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a> <span class="at">cex =</span> <span class="fl">1.5</span>, </span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a> <span class="at">line =</span> <span class="fl">1.7</span>, </span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a> <span class="at">font =</span> <span class="dv">1</span>, </span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a> <span class="at">inner =</span> <span class="cn">FALSE</span></span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="arrow-orientation" class="level3" data-number="5.2.4">
<h3 data-number="5.2.4" class="anchored" data-anchor-id="arrow-orientation"><span class="header-section-number">5.2.4</span> Arrow orientation</h3>
<p>The function <code>mf_arrow()</code> allows you to choose the position and aspect of orientation arrow.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_arrow</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/north-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="scale" class="level3" data-number="5.2.5">
<h3 data-number="5.2.5" class="anchored" data-anchor-id="scale"><span class="header-section-number">5.2.5</span> Scale</h3>
<p>The function <code>mf_scale()</code> allows you to choose the position and the aspect of the scale.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_scale</span>(</span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a> <span class="at">size =</span> <span class="dv">60</span>,</span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a> <span class="at">lwd =</span> <span class="dv">1</span>,</span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a> <span class="at">cex =</span> <span class="fl">0.7</span></span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/scale-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="credits" class="level3" data-number="5.2.6">
<h3 data-number="5.2.6" class="anchored" data-anchor-id="credits"><span class="header-section-number">5.2.6</span> Credits</h3>
<p>The function <code>mf_credits()</code> displays a line of credits (sources, author, etc.).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_credits</span>(<span class="st">"IRD</span><span class="sc">\n</span><span class="st">Institut Pasteur du Cambodge, 2022"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/credit-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="complete-dressing" class="level3" data-number="5.2.7">
<h3 data-number="5.2.7" class="anchored" data-anchor-id="complete-dressing"><span class="header-section-number">5.2.7</span> Complete dressing</h3>
<p>The function <code>mf_layout()</code> displays all these elements.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_layout</span>(</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"Cambodia"</span>,</span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a> <span class="at">credits =</span> <span class="st">"IRD</span><span class="sc">\n</span><span class="st">Institut Pasteur du Cambodge, 2022"</span>,</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a> <span class="at">arrow =</span> <span class="cn">TRUE</span></span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/layout1-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="annotations" class="level3" data-number="5.2.8">
<h3 data-number="5.2.8" class="anchored" data-anchor-id="annotations"><span class="header-section-number">5.2.8</span> Annotations</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_annotation</span>(district[district<span class="sc">$</span>ADM2_EN <span class="sc">==</span> <span class="st">"Bakan"</span>,], <span class="at">txt =</span> <span class="st">"Bakan"</span>, <span class="at">col_txt =</span> <span class="st">"darkred"</span>, <span class="at">halo =</span> <span class="cn">TRUE</span>, <span class="at">cex =</span> <span class="fl">1.5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="legends" class="level3" data-number="5.2.9">
<h3 data-number="5.2.9" class="anchored" data-anchor-id="legends"><span class="header-section-number">5.2.9</span> Legends</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_legend</span>(</span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"prop"</span>, </span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a> <span class="at">val =</span> <span class="fu">c</span>(<span class="dv">1000</span>,<span class="dv">500</span>,<span class="dv">200</span>,<span class="dv">10</span>), </span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a> <span class="at">inches =</span> .<span class="dv">2</span>, </span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"Population"</span>, </span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a> <span class="at">pos =</span> <span class="st">"topleft"</span></span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_legend</span>(</span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a> <span class="at">type =</span> <span class="st">"choro"</span>, </span>
<span id="cb28-11"><a href="#cb28-11" aria-hidden="true" tabindex="-1"></a> <span class="at">val =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">10</span>,<span class="dv">20</span>,<span class="dv">30</span>,<span class="dv">40</span>),</span>
<span id="cb28-12"><a href="#cb28-12" aria-hidden="true" tabindex="-1"></a> <span class="at">pal =</span> <span class="st">"Greens"</span>, </span>
<span id="cb28-13"><a href="#cb28-13" aria-hidden="true" tabindex="-1"></a> <span class="at">pos =</span> <span class="st">"bottomright"</span>, </span>
<span id="cb28-14"><a href="#cb28-14" aria-hidden="true" tabindex="-1"></a> <span class="at">val_rnd =</span> <span class="dv">0</span></span>
<span id="cb28-15"><a href="#cb28-15" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="labels" class="level3" data-number="5.2.10">
<h3 data-number="5.2.10" class="anchored" data-anchor-id="labels"><span class="header-section-number">5.2.10</span> Labels</h3>
<p>The function <code>mf_label()</code> is dedicated to displaying labels.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>dist_selected <span class="ot"><-</span> district[<span class="fu">st_intersects</span>(district, district[district<span class="sc">$</span>ADM2_EN <span class="sc">==</span> <span class="st">"Bakan"</span>, ], <span class="at">sparse =</span> F), ]</span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_selected)</span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_label</span>(</span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> dist_selected,</span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a> <span class="at">var =</span> <span class="st">"ADM2_EN"</span>,</span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a> <span class="at">col=</span> <span class="st">"darkgreen"</span>,</span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a> <span class="at">halo =</span> <span class="cn">TRUE</span>,</span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a> <span class="at">overlap =</span> <span class="cn">FALSE</span>, </span>
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true" tabindex="-1"></a> <span class="at">lines =</span> <span class="cn">FALSE</span></span>
<span id="cb29-11"><a href="#cb29-11" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb29-12"><a href="#cb29-12" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_scale</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/labs-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>The argument <code>halo = TRUE</code> allows to display a slight halo around the labels and the argument <code>overlap = FALSE</code> allows to create non-overlapping labels.</p>
</section>
<section id="center-the-map-on-a-region" class="level3" data-number="5.2.11">
<h3 data-number="5.2.11" class="anchored" data-anchor-id="center-the-map-on-a-region"><span class="header-section-number">5.2.11</span> Center the map on a region</h3>
<p>The function <code>mf_init()</code> allows you to initialize a map by centering it on a spatial object.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb30"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_init</span>(<span class="at">x =</span> dist_selected)</span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_selected, <span class="at">col =</span> <span class="cn">NA</span>, <span class="at">border =</span> <span class="st">"#29a3a3"</span>, <span class="at">lwd =</span> <span class="dv">2</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="displaying-several-maps-on-the-same-figure" class="level3" data-number="5.2.12">
<h3 data-number="5.2.12" class="anchored" data-anchor-id="displaying-several-maps-on-the-same-figure"><span class="header-section-number">5.2.12</span> Displaying several maps on the same figure</h3>
<p>Here you have to use <code>mfrow</code> of the function <code>par()</code>. The first digit represents the number of of rows and second the number of columns.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="co"># define the figure layout (1 row, 2 columns)</span></span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a><span class="fu">par</span>(<span class="at">mfrow =</span> <span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">2</span>))</span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a><span class="co"># first map</span></span>
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb31-6"><a href="#cb31-6" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district, <span class="st">"Male"</span>, <span class="st">"prop"</span>, <span class="at">val_max =</span> <span class="dv">300000</span>)</span>
<span id="cb31-7"><a href="#cb31-7" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population, male"</span>)</span>
<span id="cb31-8"><a href="#cb31-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-9"><a href="#cb31-9" aria-hidden="true" tabindex="-1"></a><span class="co"># second map</span></span>
<span id="cb31-10"><a href="#cb31-10" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district)</span>
<span id="cb31-11"><a href="#cb31-11" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district, <span class="st">"Female"</span>, <span class="st">"prop"</span>, <span class="at">val_max =</span> <span class="dv">300000</span>)</span>
<span id="cb31-12"><a href="#cb31-12" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population, female"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/mfrow0-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="exporting-maps" class="level3" data-number="5.2.13">
<h3 data-number="5.2.13" class="anchored" data-anchor-id="exporting-maps"><span class="header-section-number">5.2.13</span> Exporting maps</h3>
<p>It is quite difficult to export figures (maps or others) whose height/width ratio is satisfactory. The default ratio of figures in png format is 1 (480x480 pixels):</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a>dist_filter <span class="ot"><-</span> district[district<span class="sc">$</span>ADM2_PCODE <span class="sc">==</span> <span class="st">"KH0808"</span>, ]</span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a><span class="fu">png</span>(<span class="st">"img/dist_filter_1.png"</span>)</span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_filter)</span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Filtered district"</span>)</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="img/dist_filter_1.png" class="img-fluid figure-img"></p>
</figure>
</div>
<p>On this map a lot of space is lost to the left and right of the district.</p>
<p>The function <code>mf_export()</code> allows exports of maps whose height/width ratio is controlled and corresponds to that of a spatial object.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_export</span>(dist_filter, <span class="st">"img/dist_filter_2.png"</span>, <span class="at">width =</span> <span class="dv">480</span>)</span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_filter)</span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Filtered district"</span>)</span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true" tabindex="-1"></a><span class="fu">dev.off</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="img/dist_filter_2.png" class="img-fluid figure-img" width="218"></p>
</figure>
</div>
<p>The extent of this map is exactly that of the displayed region.</p>
</section>
<section id="adding-an-image-to-a-map" class="level3" data-number="5.2.14">
<h3 data-number="5.2.14" class="anchored" data-anchor-id="adding-an-image-to-a-map"><span class="header-section-number">5.2.14</span> Adding an image to a map</h3>
<p>This can be useful for adding a logo, a pictograph. The function <code>readPNG()</code> of package <code>png</code> allows the additional images on the figure.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"default"</span>, <span class="at">mar =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">0</span>,<span class="dv">0</span>,<span class="dv">0</span>))</span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(png)</span>
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-4"><a href="#cb34-4" aria-hidden="true" tabindex="-1"></a>logo <span class="ot"><-</span> <span class="fu">readPNG</span>(<span class="st">"img/ird_logo.png"</span>) <span class="co">#Import image</span></span>
<span id="cb34-5"><a href="#cb34-5" aria-hidden="true" tabindex="-1"></a>pp <span class="ot"><-</span> <span class="fu">dim</span>(logo)[<span class="dv">2</span><span class="sc">:</span><span class="dv">1</span>]<span class="sc">*</span><span class="dv">200</span> <span class="co">#Image dimension in map unit (width and height of the original image)</span></span>
<span id="cb34-6"><a href="#cb34-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb34-7"><a href="#cb34-7" aria-hidden="true" tabindex="-1"></a><span class="co">#The upper left corner of the department's bounding box</span></span>
<span id="cb34-8"><a href="#cb34-8" aria-hidden="true" tabindex="-1"></a>xy <span class="ot"><-</span> <span class="fu">st_bbox</span>(district)[<span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">4</span>)]</span>
<span id="cb34-9"><a href="#cb34-9" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district, <span class="at">col =</span> <span class="st">"#D1914D"</span>, <span class="at">border =</span> <span class="st">"white"</span>)</span>
<span id="cb34-10"><a href="#cb34-10" aria-hidden="true" tabindex="-1"></a><span class="fu">rasterImage</span>(</span>
<span id="cb34-11"><a href="#cb34-11" aria-hidden="true" tabindex="-1"></a> <span class="at">image =</span> logo,</span>
<span id="cb34-12"><a href="#cb34-12" aria-hidden="true" tabindex="-1"></a> <span class="at">xleft =</span> xy[<span class="dv">1</span>] ,</span>
<span id="cb34-13"><a href="#cb34-13" aria-hidden="true" tabindex="-1"></a> <span class="at">ybottom =</span> xy[<span class="dv">2</span>] <span class="sc">-</span> pp[<span class="dv">2</span>],</span>
<span id="cb34-14"><a href="#cb34-14" aria-hidden="true" tabindex="-1"></a> <span class="at">xright =</span> xy[<span class="dv">1</span>] <span class="sc">+</span> pp[<span class="dv">1</span>],</span>
<span id="cb34-15"><a href="#cb34-15" aria-hidden="true" tabindex="-1"></a> <span class="at">ytop =</span> xy[<span class="dv">2</span>]</span>
<span id="cb34-16"><a href="#cb34-16" aria-hidden="true" tabindex="-1"></a>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-display">
<p><img src="05-mapping_with_r_files/figure-html/logo-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="place-an-item-precisely-on-the-map" class="level3" data-number="5.2.15">
<h3 data-number="5.2.15" class="anchored" data-anchor-id="place-an-item-precisely-on-the-map"><span class="header-section-number">5.2.15</span> Place an item precisely on the map</h3>
<p>The function <code>locator()</code> allows clicking on the figure and obtaining the coordinate of a point in the coordinate system of the figure (of the map).</p>
<div class="cell">
<pre class="place cell-code"><code># locator(1) # click to get coordinate on map
# points(locator(1)) # click to plot point on map
# text(locator(1), # click to place the item on map
# labels ="Located any texts on map",
# adj = c(0,0))
</code></pre>
</div>
<p><video src="img/locator.webm" class="img-fluid" controls=""><a href="img/locator.webm">Video</a></video></p>
<p><code>locator()</code>peut être utilisée sur la plupart des graphiques (pas ceux produits avec <code>ggplot2</code>).</p>
<div class="callout-note callout callout-style-simple no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<p><a href="https://rgeomatic.hypotheses.org/1837">How to interactively position legends and layout elements on a map with cartography</a></p>
</div>