Skip to content
Snippets Groups Projects
05-mapping_with_r.html 145.16 KiB
<!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&nbsp; 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="./06-advanced_spatial_analysis.html" rel="next">
<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>&nbsp; <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>&nbsp; <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>&nbsp; <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>&nbsp; <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>&nbsp; <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>&nbsp; <span class="chapter-title">Mapping With R</span></a>
  </div>
</li>
        <li class="sidebar-item">
  <div class="sidebar-item-container"> 
  <a href="./06-advanced_spatial_analysis.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Advanced Spatial Analysis</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">7</span>&nbsp; <span class="chapter-title">Basic statistics for spatial analysis</span></a>
  </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>&nbsp; <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">&lt;-</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>
<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>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>population <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">"data_cambodia/khm_admpop_adm2_2016_v2.csv"</span>)</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>population <span class="ot">&lt;-</span> population[, <span class="fu">c</span>(<span class="st">"ADM2_PCODE"</span>, <span class="st">"T_TL"</span>)]</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Remove commas</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>population<span class="sc">$</span>T_TL <span class="ot">&lt;-</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>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>cases <span class="ot">&lt;-</span> <span class="fu">lengths</span>(<span class="fu">st_intersects</span>(district, cases))</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>district <span class="ot">&lt;-</span> <span class="fu">merge</span>(district,</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>                  population,</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a>                  <span class="at">by =</span> <span class="st">"ADM2_PCODE"</span>)</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>incidence <span class="ot">&lt;-</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>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(<span class="at">x =</span> district,</span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a>       <span class="at">var =</span> <span class="st">"incidence"</span>,</span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a>       <span class="at">type =</span> <span class="st">"choro"</span>,</span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a>       <span class="at">leg_title =</span> <span class="st">"Incidence (per 100 000)"</span>)</span>
<span id="cb6-17"><a href="#cb6-17" 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>
<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">&lt;-</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">&lt;-</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">"&lt;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">&lt;-</span> <span class="fu">st_centroid</span>(district[district<span class="sc">$</span>Status <span class="sc">!=</span> <span class="st">"&lt;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">&lt;-</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">&lt;-</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">"&lt;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">&lt;-</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">&lt;-</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">&lt;-</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">&lt;-</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">&lt;-</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">&lt;-</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">&lt;-</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>
</div>
</div>
</section>
<section id="add-shading-to-a-layer" class="level3" data-number="5.2.16">
<h3 data-number="5.2.16" class="anchored" data-anchor-id="add-shading-to-a-layer"><span class="header-section-number">5.2.16</span> Add shading to a layer</h3>
<p>The function <code>mf_shadow()</code> allows to create a shadow to a layer of polygons.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb36"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_shadow</span>(district)</span>
<span id="cb36-2"><a href="#cb36-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></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/shadow-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="creating-boxes" class="level3" data-number="5.2.17">
<h3 data-number="5.2.17" class="anchored" data-anchor-id="creating-boxes"><span class="header-section-number">5.2.17</span> Creating Boxes</h3>
<p>The function <code>mf_inset_on()</code> allows to start creation a box. You must then “close” the box with <code>mf_inset_off()</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_init</span>(<span class="at">x =</span> dist_selected, <span class="at">theme =</span> <span class="st">"agolalight"</span>, <span class="at">expandBB =</span> <span class="fu">c</span>(<span class="dv">0</span>,.<span class="dv">1</span>,<span class="dv">0</span>,.<span class="dv">5</span>)) </span>
<span id="cb37-2"><a href="#cb37-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="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_selected, <span class="at">col =</span> <span class="st">"tomato4"</span>, <span class="at">border =</span> <span class="st">"tomato1"</span>, <span class="at">lwd =</span> <span class="dv">2</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb37-4"><a href="#cb37-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-5"><a href="#cb37-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Cambodia inset box</span></span>
<span id="cb37-6"><a href="#cb37-6" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_on</span>(<span class="at">x =</span> country, <span class="at">pos =</span> <span class="st">"topright"</span>, <span class="at">cex =</span> .<span class="dv">3</span>)</span>
<span id="cb37-7"><a href="#cb37-7" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(country, <span class="at">lwd =</span> .<span class="dv">5</span>, <span class="at">border=</span> <span class="st">"grey90"</span>)</span>
<span id="cb37-8"><a href="#cb37-8" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_selected, <span class="at">col =</span> <span class="st">"tomato4"</span>, <span class="at">border =</span> <span class="st">"tomato1"</span>, <span class="at">lwd =</span> .<span class="dv">5</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb37-9"><a href="#cb37-9" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_scale</span>(<span class="at">size =</span> <span class="dv">100</span>, <span class="at">pos =</span> <span class="st">"bottomleft"</span>, <span class="at">cex =</span> .<span class="dv">6</span>, <span class="at">lwd =</span> .<span class="dv">5</span>)</span>
<span id="cb37-10"><a href="#cb37-10" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_off</span>()</span>
<span id="cb37-11"><a href="#cb37-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-12"><a href="#cb37-12" aria-hidden="true" tabindex="-1"></a><span class="co"># District inset box</span></span>
<span id="cb37-13"><a href="#cb37-13" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_on</span>(<span class="at">x =</span> district, <span class="at">pos =</span> <span class="st">"bottomright"</span>, <span class="at">cex =</span> .<span class="dv">3</span>)</span>
<span id="cb37-14"><a href="#cb37-14" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district, <span class="at">lwd =</span> <span class="fl">0.5</span>, <span class="at">border=</span> <span class="st">"grey90"</span>)</span>
<span id="cb37-15"><a href="#cb37-15" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_selected, <span class="at">col =</span> <span class="st">"tomato4"</span>, <span class="at">border =</span> <span class="st">"tomato1"</span>, <span class="at">lwd =</span> .<span class="dv">5</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb37-16"><a href="#cb37-16" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_scale</span>(<span class="at">size =</span> <span class="dv">100</span>, <span class="at">pos =</span> <span class="st">"bottomright"</span>, <span class="at">cex =</span> .<span class="dv">6</span>, <span class="at">lwd =</span> .<span class="dv">5</span>)</span>
<span id="cb37-17"><a href="#cb37-17" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_off</span>()</span>
<span id="cb37-18"><a href="#cb37-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-19"><a href="#cb37-19" aria-hidden="true" tabindex="-1"></a><span class="co"># World inset box</span></span>
<span id="cb37-20"><a href="#cb37-20" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_on</span>(<span class="at">x =</span> <span class="st">"worldmap"</span>, <span class="at">pos =</span> <span class="st">"topleft"</span>)</span>
<span id="cb37-21"><a href="#cb37-21" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_worldmap</span>(dist_selected, <span class="at">land_col =</span> <span class="st">"#cccccc"</span>, <span class="at">border_col =</span> <span class="cn">NA</span>, </span>
<span id="cb37-22"><a href="#cb37-22" aria-hidden="true" tabindex="-1"></a>            <span class="at">water_col =</span>  <span class="st">"#e3e3e3"</span>, <span class="at">col =</span> <span class="st">"tomato4"</span>)</span>
<span id="cb37-23"><a href="#cb37-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-24"><a href="#cb37-24" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_off</span>()</span>
<span id="cb37-25"><a href="#cb37-25" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Bakan district and its surroundings"</span>)</span>
<span id="cb37-26"><a href="#cb37-26" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_scale</span>(<span class="dv">10</span>, <span class="at">pos =</span> <span class="st">'bottomleft'</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/inset-1.png" class="img-fluid" width="624"></p>
</div>
</div>
</section>
</section>
<section id="d-maps" class="level2" data-number="5.3">
<h2 data-number="5.3" class="anchored" data-anchor-id="d-maps"><span class="header-section-number">5.3</span> 3D maps</h2>
<section id="linemap" class="level3" data-number="5.3.1">
<h3 data-number="5.3.1" class="anchored" data-anchor-id="linemap"><span class="header-section-number">5.3.1</span> linemap</h3>
<p>The package <code>linemap</code> <span class="citation" data-cites="linemap">(<a href="references.html#ref-linemap" role="doc-biblioref">Giraud 2021</a>)</span> allows you to make maps made up of lines.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb38"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><a href="#cb38-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(linemap)</span>
<span id="cb38-2"><a href="#cb38-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(mapsf)</span>
<span id="cb38-3"><a href="#cb38-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(sf)</span>
<span id="cb38-4"><a href="#cb38-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr)</span>
<span id="cb38-5"><a href="#cb38-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-6"><a href="#cb38-6" aria-hidden="true" tabindex="-1"></a>pp <span class="ot">=</span> <span class="fu">st_read</span>(<span class="st">"data_cambodia/PP.gpkg"</span>, <span class="at">quiet =</span> <span class="cn">TRUE</span>)      <span class="co"># import Phnom Penh administrative border</span></span>
<span id="cb38-7"><a href="#cb38-7" aria-hidden="true" tabindex="-1"></a>pp_pop_dens <span class="ot">&lt;-</span> <span class="fu">getgrid</span>(<span class="at">x =</span> pp, <span class="at">cellsize =</span><span class="dv">1000</span>, <span class="at">var =</span> <span class="st">"DENs"</span>)   <span class="co"># create population density in grid format  (pop density/1km)</span></span>
<span id="cb38-8"><a href="#cb38-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-9"><a href="#cb38-9" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_init</span>(pp)</span>
<span id="cb38-10"><a href="#cb38-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-11"><a href="#cb38-11" aria-hidden="true" tabindex="-1"></a><span class="fu">linemap</span>(</span>
<span id="cb38-12"><a href="#cb38-12" aria-hidden="true" tabindex="-1"></a>  <span class="at">x =</span> pp_pop_dens,  </span>
<span id="cb38-13"><a href="#cb38-13" aria-hidden="true" tabindex="-1"></a>  <span class="at">var =</span> <span class="st">"DENs"</span>,</span>
<span id="cb38-14"><a href="#cb38-14" aria-hidden="true" tabindex="-1"></a>  <span class="at">k =</span> <span class="dv">1</span>,</span>
<span id="cb38-15"><a href="#cb38-15" aria-hidden="true" tabindex="-1"></a>  <span class="at">threshold =</span> <span class="dv">5</span>, </span>
<span id="cb38-16"><a href="#cb38-16" aria-hidden="true" tabindex="-1"></a>  <span class="at">lwd =</span> <span class="dv">1</span>,</span>
<span id="cb38-17"><a href="#cb38-17" aria-hidden="true" tabindex="-1"></a>  <span class="at">col =</span> <span class="st">"ivory1"</span>,</span>
<span id="cb38-18"><a href="#cb38-18" aria-hidden="true" tabindex="-1"></a>  <span class="at">border =</span> <span class="st">"ivory4"</span>,</span>
<span id="cb38-19"><a href="#cb38-19" aria-hidden="true" tabindex="-1"></a>  <span class="at">add =</span> T)</span>
<span id="cb38-20"><a href="#cb38-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb38-21"><a href="#cb38-21" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Phnom Penh Population Density, 2019"</span>)</span>
<span id="cb38-22"><a href="#cb38-22" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_credits</span>(<span class="st">"Humanitarian Data Exchange, 2022</span><span class="sc">\n</span><span class="st">unit data:km2"</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/linemap-1.png" class="img-fluid" width="672"></p>
</div>
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a><span class="co"># url = "https://data.humdata.org/dataset/1803994d-6218-4b98-ac3a-30c7f85c6dbc/resource/f30b0f4b-1c40-45f3-986d-2820375ea8dd/download/health_facility.zip"</span></span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a><span class="co"># health_facility.zip = "health_facility.zip"</span></span>
<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a><span class="co"># download.file(url, destfile = health_facility.zip)</span></span>
<span id="cb39-4"><a href="#cb39-4" aria-hidden="true" tabindex="-1"></a><span class="co"># unzip(health_facility.zip) # Unzipped files are in a new folder named Health</span></span>
<span id="cb39-5"><a href="#cb39-5" aria-hidden="true" tabindex="-1"></a><span class="co"># list.files(path="Health")</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="relief-tanaka" class="level3" data-number="5.3.2">
<h3 data-number="5.3.2" class="anchored" data-anchor-id="relief-tanaka"><span class="header-section-number">5.3.2</span> Relief Tanaka</h3>
<p>We use the <code>tanaka</code> package <span class="citation" data-cites="tanaka">(<a href="references.html#ref-tanaka" role="doc-biblioref">Giraud 2022b</a>)</span> which provides a method <span class="citation" data-cites="tanaka1950">(<a href="references.html#ref-tanaka1950" role="doc-biblioref">Tanaka 1950</a>)</span> used to improve the perception of relief.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb40"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><a href="#cb40-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tanaka)</span>
<span id="cb40-2"><a href="#cb40-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(terra)</span>
<span id="cb40-3"><a href="#cb40-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-4"><a href="#cb40-4" aria-hidden="true" tabindex="-1"></a>rpop <span class="ot">&lt;-</span> <span class="fu">rast</span>(<span class="st">"data_cambodia/khm_pd_2019_1km_utm.tif"</span>)     <span class="co"># Import population raster data (in UTM)</span></span>
<span id="cb40-5"><a href="#cb40-5" 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 Cambodian districts layer</span></span>
<span id="cb40-6"><a href="#cb40-6" aria-hidden="true" tabindex="-1"></a>district <span class="ot">&lt;-</span> <span class="fu">st_transform</span>(district, <span class="fu">st_crs</span>(rpop))    <span class="co"># Transform data into the same coordinate system</span></span>
<span id="cb40-7"><a href="#cb40-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-8"><a href="#cb40-8" aria-hidden="true" tabindex="-1"></a>mat <span class="ot">&lt;-</span> <span class="fu">focalMat</span>(<span class="at">x =</span> rpop, <span class="at">d =</span> <span class="fu">c</span>(<span class="dv">1500</span>), <span class="at">type =</span> <span class="st">"Gauss"</span>)  <span class="co"># Raster smoothing</span></span>
<span id="cb40-9"><a href="#cb40-9" aria-hidden="true" tabindex="-1"></a>rpopl <span class="ot">&lt;-</span> <span class="fu">focal</span>(<span class="at">x =</span> rpop, <span class="at">w =</span> mat, <span class="at">fun =</span> sum, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)</span>
<span id="cb40-10"><a href="#cb40-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb40-11"><a href="#cb40-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Mapping</span></span>
<span id="cb40-12"><a href="#cb40-12" aria-hidden="true" tabindex="-1"></a>cols <span class="ot">&lt;-</span> <span class="fu">hcl.colors</span>(<span class="dv">8</span>, <span class="st">"Reds"</span>, <span class="at">alpha =</span> <span class="dv">1</span>, <span class="at">rev =</span> T)[<span class="sc">-</span><span class="dv">1</span>]</span>
<span id="cb40-13"><a href="#cb40-13" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_theme</span>(<span class="st">"agolalight"</span>)</span>
<span id="cb40-14"><a href="#cb40-14" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_init</span>(district)</span>
<span id="cb40-15"><a href="#cb40-15" aria-hidden="true" tabindex="-1"></a><span class="fu">tanaka</span>(<span class="at">x =</span> rpop, <span class="at">breaks =</span> <span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">10</span>,<span class="dv">25</span>,<span class="dv">50</span>,<span class="dv">100</span>,<span class="dv">250</span>,<span class="dv">500</span>,<span class="dv">64265</span>),</span>
<span id="cb40-16"><a href="#cb40-16" aria-hidden="true" tabindex="-1"></a>       <span class="at">col =</span> cols, <span class="at">add =</span> T, <span class="at">mask =</span> district, <span class="at">legend.pos =</span> <span class="st">"n"</span>)</span>
<span id="cb40-17"><a href="#cb40-17" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_legend</span>(<span class="at">type =</span> <span class="st">"choro"</span>, <span class="at">pos =</span> <span class="st">"bottomright"</span>, </span>
<span id="cb40-18"><a href="#cb40-18" 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">25</span>,<span class="dv">50</span>,<span class="dv">100</span>,<span class="dv">250</span>,<span class="dv">500</span>,<span class="dv">64265</span>), <span class="at">pal =</span> cols,</span>
<span id="cb40-19"><a href="#cb40-19" aria-hidden="true" tabindex="-1"></a>          <span class="at">bg =</span> <span class="st">"#EDF4F5"</span>, <span class="at">fg =</span> <span class="cn">NA</span>, <span class="at">frame =</span> T, <span class="at">val_rnd =</span> <span class="dv">0</span>,</span>
<span id="cb40-20"><a href="#cb40-20" aria-hidden="true" tabindex="-1"></a>          <span class="at">title =</span> <span class="st">"Population</span><span class="sc">\n</span><span class="st">per km2"</span>)</span>
<span id="cb40-21"><a href="#cb40-21" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population density of Cambodia, 2019"</span>)</span>
<span id="cb40-22"><a href="#cb40-22" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_credits</span>(<span class="st">"Humanitarian Data Exchange, 2022"</span>,</span>
<span id="cb40-23"><a href="#cb40-23" aria-hidden="true" tabindex="-1"></a>           <span class="at">bg =</span> <span class="st">"#EDF4F5"</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/tanaka-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<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/1758">The tanaka package</a></p>
</div>
</div>
</div>
</section>
</section>
<section id="cartographic-transformation" class="level2" data-number="5.4">
<h2 data-number="5.4" class="anchored" data-anchor-id="cartographic-transformation"><span class="header-section-number">5.4</span> Cartographic Transformation</h2>
<blockquote class="blockquote">
<p>classical anamorphosis is a representation of States(or any cells) by <strong>rectangle or any polygons</strong> according to a <strong>quantities</strong> attached to them. (…) We strive to <strong>keep the general arrangement</strong> of meshes or the silhouette of the continent.”<br>
<span class="citation" data-cites="Brunet93">Brunet, Ferras, and Théry (<a href="references.html#ref-Brunet93" role="doc-biblioref">1993</a>)</span></p>
</blockquote>
<p>3 types of anamorphoses or cartograms are presented here:</p>
<ul>
<li>Dorling’s cartograms <span class="citation" data-cites="Dorling96">(<a href="references.html#ref-Dorling96" role="doc-biblioref">Dorling 1996</a>)</span></li>
<li>Non-contiguous cartograms <span class="citation" data-cites="Olson76">(<a href="references.html#ref-Olson76" role="doc-biblioref">Olson 1976</a>)</span></li>
<li>Contiguous cartograms <span class="citation" data-cites="Dougenik85">(<a href="references.html#ref-Dougenik85" role="doc-biblioref">Dougenik, Chrisman, and Niemeyer 1985</a>)</span></li>
</ul>
<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 comprehensive course on anamorphoses : <a href="https://neocarto.hypotheses.org/366">Les anamorphoses cartographiques</a> <span class="citation" data-cites="Lambert15">(<a href="references.html#ref-Lambert15" role="doc-biblioref">Lambert 2015</a>)</span>.</p>
</div>
</div>
</div>
<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/1361">Make cartograms with R</a></p>
</div>
</div>
</div>
<p>To make the cartograms we use the package <code>cartogram</code> <span class="citation" data-cites="cartogram">(<a href="references.html#ref-cartogram" role="doc-biblioref">Jeworutzki 2020</a>)</span>.</p>
<section id="dorlings-cartograms" class="level3" data-number="5.4.1">
<h3 data-number="5.4.1" class="anchored" data-anchor-id="dorlings-cartograms"><span class="header-section-number">5.4.1</span> Dorling’s cartograms</h3>
<p>The territories are represented by figures (circles, squares or rectangles) which do not overlap, the surface of which are proportional to a variable. The proportion of the figures are defined according to the starting positions.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="img/dorling.png" class="img-fluid figure-img" width="600"></p>
</figure>
</div>
<div class="cell" type="rmdmoins">

<div class="rmdmoins">
Space is quite poorly identified.<br>
You can name the circles to get your bearings and/or use the color to make clusters appear and better identify the geographical blocks.
</div>
</div>
<div class="cell" type="rmdplus">

<div class="rmdplus">
The perception of quantities is very good. The circle sizes are really comarable.
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(mapsf)</span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(cartogram)</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a>district <span class="ot">&lt;-</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="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a>dist_dorling <span class="ot">&lt;-</span> <span class="fu">cartogram_dorling</span>(<span class="at">x =</span> district, <span class="at">weight =</span> <span class="st">"T_POP"</span>, <span class="at">k =</span> <span class="fl">0.7</span>)</span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_dorling, <span class="at">col =</span> <span class="st">"#40E0D0"</span>, <span class="at">border=</span> <span class="st">"white"</span>)</span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_label</span>(</span>
<span id="cb41-7"><a href="#cb41-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">x =</span> dist_dorling[<span class="fu">order</span>(dist_dorling<span class="sc">$</span>T_POP, <span class="at">decreasing =</span> <span class="cn">TRUE</span>), ][<span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>,], </span>
<span id="cb41-8"><a href="#cb41-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">var =</span> <span class="st">"ADM2_EN"</span>,</span>
<span id="cb41-9"><a href="#cb41-9" aria-hidden="true" tabindex="-1"></a>  <span class="at">overlap =</span> <span class="cn">FALSE</span>, </span>
<span id="cb41-10"><a href="#cb41-10" aria-hidden="true" tabindex="-1"></a>  <span class="co"># show.lines = FALSE,</span></span>
<span id="cb41-11"><a href="#cb41-11" aria-hidden="true" tabindex="-1"></a>  <span class="at">halo =</span> <span class="cn">TRUE</span>, </span>
<span id="cb41-12"><a href="#cb41-12" aria-hidden="true" tabindex="-1"></a>  <span class="at">r =</span> <span class="fl">0.15</span></span>
<span id="cb41-13"><a href="#cb41-13" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb41-14"><a href="#cb41-14" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population of District - Dorling Cartogram"</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/dorling-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>The parameter <code>k</code> allows to vary the expansion factor of the circles.</p>
</section>
<section id="non-continuous-cartograms" class="level3" data-number="5.4.2">
<h3 data-number="5.4.2" class="anchored" data-anchor-id="non-continuous-cartograms"><span class="header-section-number">5.4.2</span> Non-continuous cartograms</h3>
<p>The size of the polygons is proportional to a variable. The arrangement of the polygons relative to each other is preserved. The shape of the polygons is similar.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="img/nccartogram.png" class="img-fluid figure-img"></p>
</figure>
</div>
<p><span class="citation" data-cites="Cauvin13">(<a href="references.html#ref-Cauvin13" role="doc-biblioref">Cauvin, Escobar, and Serradj 2013</a>)</span></p>
<div class="cell" type="rmdmoins">

<div class="rmdmoins">
The topology of the regions is lost.
</div>
</div>
<div class="cell" type="rmdplus">

<div class="rmdplus">
The converstion of the polygons shape is optimal.
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb42"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1"><a href="#cb42-1" aria-hidden="true" tabindex="-1"></a>dist_ncont <span class="ot">&lt;-</span> <span class="fu">cartogram_ncont</span>(<span class="at">x =</span> district, <span class="at">weight =</span> <span class="st">"T_POP"</span>, <span class="at">k =</span> <span class="fl">1.2</span>)</span>
<span id="cb42-2"><a href="#cb42-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district, <span class="at">col =</span> <span class="cn">NA</span>, <span class="at">border =</span> <span class="st">"#FDFEFE"</span>, <span class="at">lwd =</span> <span class="fl">1.5</span>)</span>
<span id="cb42-3"><a href="#cb42-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_ncont, <span class="at">col =</span> <span class="st">"#20B2AA"</span>, <span class="at">border=</span> <span class="st">"white"</span>, <span class="at">add =</span> <span class="cn">TRUE</span>)</span>
<span id="cb42-4"><a href="#cb42-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population of District - Non-continuous cartograms"</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/olson-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>The parameter <code>k</code> allows to vary the expansion of the polygons.</p>
</section>
<section id="continuous-cartograms" class="level3" data-number="5.4.3">
<h3 data-number="5.4.3" class="anchored" data-anchor-id="continuous-cartograms"><span class="header-section-number">5.4.3</span> Continuous cartograms</h3>
<p>The size of the polygons is proportional to variable. The arrangement of the polygons relative to each other is preserved. To maintain contiguity, the sape of the polygons is heavily transformed.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="img/cartogram.jpg" class="img-fluid figure-img" width="600"></p>
</figure>
</div>
<p><span class="citation" data-cites="Paull16">(<a href="references.html#ref-Paull16" role="doc-biblioref">Paull and Hennig 2016</a>)</span></p>
<div class="cell" type="rmdmoins">

<div class="rmdmoins">
The shape of the polygond is strongly distorted.
</div>
</div>
<div class="cell" type="rmdplus">

<div class="rmdplus">
<p>It is a “real geographical map”: topology and contiguity are preserved.</p>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a>dist_ncont <span class="ot">&lt;-</span> <span class="fu">cartogram_cont</span>(<span class="at">x =</span> district, <span class="at">weight =</span> <span class="st">"DENs"</span>, <span class="at">maxSizeError =</span> <span class="dv">6</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 1: 15.8686749410166</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 2: 12.1107731631101</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 3: 9.98940057337996</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 4: 8.62323208787643</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 5: 7.60706404894655</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 6: 6.83561617758241</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 7: 10.1399490743501</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Mean size error for iteration 8: 5.79418495291592</code></pre>
</div>
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(dist_ncont, <span class="at">col =</span> <span class="st">"#66CDAA"</span>, <span class="at">border=</span> <span class="st">"white"</span>, <span class="at">add =</span> <span class="cn">FALSE</span>)</span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_title</span>(<span class="st">"Population of District - Continuous cartograms"</span>)</span>
<span id="cb52-3"><a href="#cb52-3" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_on</span>(district, <span class="at">cex =</span> .<span class="dv">2</span>, <span class="at">pos =</span> <span class="st">"bottomleft"</span>)</span>
<span id="cb52-4"><a href="#cb52-4" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_map</span>(district, <span class="at">lwd =</span> .<span class="dv">5</span>)</span>
<span id="cb52-5"><a href="#cb52-5" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_inset_off</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/dougenik-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
<section id="stengths-and-weaknessses-of-cartograms" class="level3" data-number="5.4.4">
<h3 data-number="5.4.4" class="anchored" data-anchor-id="stengths-and-weaknessses-of-cartograms"><span class="header-section-number">5.4.4</span> Stengths and weaknessses of cartograms</h3>
<p>cartograms are cartographic representations perceived as <strong>innovative</strong> (although the method is 40 years old). These very generalize images capture <strong>quantities</strong> and <strong>gradients</strong> well. These are real <strong>communication</strong> images that <strong>provoke</strong>, arouse <strong>interest</strong>, convey a strong <strong>message</strong>, <strong>challenge</strong>.</p>
<p>But cartograms induce a loss of <strong>visual cues</strong> (difficult to find one’s country or region on the map), require a <strong>reading effort</strong> which can be significant and do not make it possible to manage <strong>missing data</strong>.</p>


<div id="refs" class="references csl-bib-body hanging-indent" role="doc-bibliography" style="display: none">
<div id="ref-Brunet93" class="csl-entry" role="doc-biblioentry">
Brunet, Roger, Robert Ferras, and Hervé Théry. 1993. <em>Les Mots de La g<span>é</span>ographie: Dictionnaire Critique</em>. 03) 911 BRU.
</div>
<div id="ref-Cauvin13" class="csl-entry" role="doc-biblioentry">
Cauvin, Colette, Francisco Escobar, and Aziz Serradj. 2013. <em>Thematic Cartography, Cartography and the Impact of the Quantitative Revolution</em>. Vol. 2. John Wiley &amp; Sons.
</div>
<div id="ref-Dorling96" class="csl-entry" role="doc-biblioentry">
Dorling, Daniel. 1996. <em>Area Cartograms: Their Use and Creation, Concepts and Techniques in Modern Geography</em>. Vol. 59. CATMOG: Concepts and Techniques in Modern Geography. Institute of British Geographers.
</div>
<div id="ref-Dougenik85" class="csl-entry" role="doc-biblioentry">
Dougenik, James A, Nicholas R Chrisman, and Duane R Niemeyer. 1985. <span>“An Algorithm to Construct Continuous Area Cartograms.”</span> <em>The Professional Geographer</em> 37 (1): 75–81.
</div>
<div id="ref-linemap" class="csl-entry" role="doc-biblioentry">
Giraud, Timothée. 2021. <span>“Linemap: Line Maps.”</span> <a href="https://CRAN.R-project.org/package=linemap">https://CRAN.R-project.org/package=linemap</a>.
</div>
<div id="ref-mapsf" class="csl-entry" role="doc-biblioentry">
———. 2022a. <span>“Mapsf: Thematic Cartography.”</span> <a href="https://CRAN.R-project.org/package=mapsf">https://CRAN.R-project.org/package=mapsf</a>.
</div>
<div id="ref-tanaka" class="csl-entry" role="doc-biblioentry">
———. 2022b. <span>“Tanaka: Design Shaded Contour Lines (or Tanaka) Maps.”</span> <a href="https://CRAN.R-project.org/package=tanaka">https://CRAN.R-project.org/package=tanaka</a>.
</div>
<div id="ref-cartogram" class="csl-entry" role="doc-biblioentry">
Jeworutzki, Sebastian. 2020. <span>“Cartogram: Create Cartograms with r.”</span> <a href="https://CRAN.R-project.org/package=cartogram">https://CRAN.R-project.org/package=cartogram</a>.
</div>
<div id="ref-Lambert15" class="csl-entry" role="doc-biblioentry">
Lambert, Nicolas. 2015. <span>“Les Anamorphoses Cartographiques.”</span> Blog. <em>Carnet Néocartographique</em>. <a href="https://neocarto.hypotheses.org/366" class="uri">https://neocarto.hypotheses.org/366</a>.
</div>
<div id="ref-Olson76" class="csl-entry" role="doc-biblioentry">
Olson, Judy M. 1976. <span>“Noncontiguous Area Cartograms.”</span> <em>The Professional Geographer</em> 28 (4): 371–80.
</div>
<div id="ref-Paull16" class="csl-entry" role="doc-biblioentry">
Paull, John, and Benjamin Hennig. 2016. <span>“Atlas of Organics: Four Maps of the World of Organic Agriculture.”</span> <em>Journal of Organics</em> 3 (1): 25–32.
</div>
<div id="ref-tanaka1950" class="csl-entry" role="doc-biblioentry">
Tanaka, Kitiro. 1950. <span>“The Relief Contour Method of Representing Topography on Maps.”</span> <em>Geographical Review</em> 40 (3): 444. <a href="https://doi.org/10.2307/211219">https://doi.org/10.2307/211219</a>.
</div>
</div>
</section>
</section>

</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
  const toggleBodyColorMode = (bsSheetEl) => {
    const mode = bsSheetEl.getAttribute("data-mode");
    const bodyEl = window.document.querySelector("body");
    if (mode === "dark") {
      bodyEl.classList.add("quarto-dark");
      bodyEl.classList.remove("quarto-light");
    } else {
      bodyEl.classList.add("quarto-light");
      bodyEl.classList.remove("quarto-dark");
    }
  }
  const toggleBodyColorPrimary = () => {
    const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
    if (bsSheetEl) {
      toggleBodyColorMode(bsSheetEl);
    }
  }
  toggleBodyColorPrimary();  
  const icon = "";
  const anchorJS = new window.AnchorJS();
  anchorJS.options = {
    placement: 'right',
    icon: icon
  };
  anchorJS.add('.anchored');
  const clipboard = new window.ClipboardJS('.code-copy-button', {
    target: function(trigger) {
      return trigger.previousElementSibling;
    }
  });
  clipboard.on('success', function(e) {
    // button target
    const button = e.trigger;
    // don't keep focus
    button.blur();
    // flash "checked"
    button.classList.add('code-copy-button-checked');
    var currentTitle = button.getAttribute("title");
    button.setAttribute("title", "Copied!");
    setTimeout(function() {
      button.setAttribute("title", currentTitle);
      button.classList.remove('code-copy-button-checked');
    }, 1000);
    // clear code selection
    e.clearSelection();
  });
  function tippyHover(el, contentFn) {
    const config = {
      allowHTML: true,
      content: contentFn,
      maxWidth: 500,
      delay: 100,
      arrow: false,
      appendTo: function(el) {
          return el.parentElement;
      },
      interactive: true,
      interactiveBorder: 10,
      theme: 'quarto',
      placement: 'bottom-start'
    };
    window.tippy(el, config); 
  }
  const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
  for (var i=0; i<noterefs.length; i++) {
    const ref = noterefs[i];
    tippyHover(ref, function() {
      // use id or data attribute instead here
      let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
      try { href = new URL(href).hash; } catch {}
      const id = href.replace(/^#\/?/, "");
      const note = window.document.getElementById(id);
      return note.innerHTML;
    });
  }
  var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
  for (var i=0; i<bibliorefs.length; i++) {
    const ref = bibliorefs[i];
    const cites = ref.parentNode.getAttribute('data-cites').split(' ');
    tippyHover(ref, function() {
      var popup = window.document.createElement('div');
      cites.forEach(function(cite) {
        var citeDiv = window.document.createElement('div');
        citeDiv.classList.add('hanging-indent');
        citeDiv.classList.add('csl-entry');
        var biblioDiv = window.document.getElementById('ref-' + cite);
        if (biblioDiv) {
          citeDiv.innerHTML = biblioDiv.innerHTML;
        }
        popup.appendChild(citeDiv);
      });
      return popup.innerHTML;
    });
  }
    var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
      var filterRegex = new RegExp('/' + window.location.host + '/');
    var isInternal = (href) => {
        return filterRegex.test(href) || localhostRegex.test(href);
    }
    // Inspect non-navigation links and adorn them if external
    var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
    for (var i=0; i<links.length; i++) {
      const link = links[i];
      if (!isInternal(link.href)) {
          // target, if specified
          link.setAttribute("target", "_blank");
      }
    }
});
</script>
<nav class="page-navigation">
  <div class="nav-page nav-page-previous">
      <a href="./04-raster_data.html" class="pagination-link">
        <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Using raster data</span></span>
      </a>          
  </div>
  <div class="nav-page nav-page-next">
      <a href="./06-advanced_spatial_analysis.html" class="pagination-link">
        <span class="nav-page-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Advanced Spatial Analysis</span></span> <i class="bi bi-arrow-right-short"></i>
      </a>
  </div>
</nav>
</div> <!-- /content -->
<footer class="footer">
  <div class="nav-footer">
    <div class="nav-footer-left">UMR 228 ESPACE-DEV</div>   
    <div class="nav-footer-right"><img src="img/ird_footer.png" height="50"></div>
  </div>
</footer>



<script src="site_libs/quarto-html/zenscroll-min.js"></script>
</body></html>