|
7 | 7 | <title>Chapter 9 Making maps with R | Geocomputation with R</title>
|
8 | 8 | <meta name="author" content="Robin Lovelace, Jakub Nowosad, Jannes Muenchow">
|
9 | 9 | <meta name="description" content="Prerequisites This chapter requires the following packages that we have already been using: library(sf) library(raster) library(dplyr) library(spData) library(spDataLarge) In addition, it uses the...">
|
10 |
| -<meta name="generator" content="bookdown 0.24 with bs4_book()"> |
| 10 | +<meta name="generator" content="bookdown 0.25 with bs4_book()"> |
11 | 11 | <meta property="og:title" content="Chapter 9 Making maps with R | Geocomputation with R">
|
12 | 12 | <meta property="og:type" content="book">
|
13 | 13 | <meta property="og:url" content="https://geocompr.robinlovelace.net/adv-map.html">
|
|
17 | 17 | <meta name="twitter:title" content="Chapter 9 Making maps with R | Geocomputation with R">
|
18 | 18 | <meta name="twitter:description" content="Prerequisites This chapter requires the following packages that we have already been using: library(sf) library(raster) library(dplyr) library(spData) library(spDataLarge) In addition, it uses the...">
|
19 | 19 | <meta name="twitter:image" content="https://geocompr.robinlovelace.net/images/cover.png">
|
20 |
| -<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/header-attrs-2.12/header-attrs.js"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| 20 | +<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
21 | 21 | <link href="libs/bootstrap-4.6.0/bootstrap.min.css" rel="stylesheet">
|
22 | 22 | <script src="libs/bootstrap-4.6.0/bootstrap.bundle.min.js"></script><link href="libs/_Lato-0.4.0/font.css" rel="stylesheet">
|
23 | 23 | <link href="libs/_Roboto%20Mono-0.4.0/font.css" rel="stylesheet">
|
|
260 | 260 | The purpose of this section is to show how.</p>
|
261 | 261 | <p>There are two main types of map aesthetics: those that change with the data and those that are constant.
|
262 | 262 | Unlike <strong>ggplot2</strong>, which uses the helper function <code><a href="https://ggplot2.tidyverse.org/reference/aes.html">aes()</a></code> to represent variable aesthetics, <strong>tmap</strong> accepts aesthetic arguments directly.
|
263 |
| -To map a variable to an aesthetic, pass its column name to the corresponding argument, and to set a fixed aesthetic, pass the desired value instead.<a href="references.html#fn42" class="footnote-ref" id="fnref42"><sup>42</sup></a> |
| 263 | +To map a variable to an aesthetic, pass its column name to the corresponding argument, and to set a fixed aesthetic, pass the desired value instead.<a class="footnote-ref" tabindex="0" data-toggle="popover" data-content="<p> |
| 264 | +If there is a clash between a fixed value and a column name, the column name takes precedence. This can be verified by running the next code chunk after running <code>nz$red = 1:nrow(nz)</code>.</p>"><sup>42</sup></a> |
264 | 265 | The most commonly used aesthetics for fill and border layers include color, transparency, line width and line type, set with <code>col</code>, <code>alpha</code>, <code>lwd</code>, and <code>lty</code> arguments, respectively.
|
265 | 266 | The impact of setting these with fixed values is illustrated in Figure <a href="adv-map.html#fig:tmstatic">9.3</a>.</p>
|
266 | 267 | <div class="sourceCode" id="cb302"><pre class="downlit sourceCode r">
|
|
366 | 367 | <p>There are three main groups of color palettes: categorical, sequential and diverging (Figure <a href="adv-map.html#fig:colpal">9.7</a>), and each of them serves a different purpose.
|
367 | 368 | Categorical palettes consist of easily distinguishable colors and are most appropriate for categorical data without any particular order such as state names or land cover classes.
|
368 | 369 | Colors should be intuitive: rivers should be blue, for example, and pastures green.
|
369 |
| -Avoid too many categories: maps with large legends and many colors can be uninterpretable.<a href="references.html#fn43" class="footnote-ref" id="fnref43"><sup>43</sup></a></p> |
| 370 | +Avoid too many categories: maps with large legends and many colors can be uninterpretable.<a class="footnote-ref" tabindex="0" data-toggle="popover" data-content='<p> |
| 371 | +<code>col = "MAP_COLORS"</code> can be used in maps with a large number of individual polygons (for example, a map of individual countries) to create unique colors for adjacent polygons.</p>'><sup>43</sup></a></p> |
370 | 372 | <p>The second group is sequential palettes.
|
371 | 373 | These follow a gradient, for example from light to dark colors (light colors tend to represent lower values), and are appropriate for continuous (numeric) variables.
|
372 | 374 | Sequential palettes can be single (<code>Blues</code> go from light to dark blue, for example) or multi-color/hue (<code>YlOrBr</code> is gradient from light yellow to brown via orange, for example), as demonstrated in the code chunk below — output not shown, run the code yourself to see the results!</p>
|
|
391 | 393 | This property is not preserved in the rainbow color palette; therefore, we suggest avoiding it in geographic data visualization <span class="citation">(<a href="references.html#ref-borland_rainbow_2007" role="doc-biblioref">Borland and Taylor II 2007</a>)</span>.
|
392 | 394 | Instead, <a href="https://cran.r-project.org/web/packages/viridis/">the viridis color palettes</a>, also available in <strong>tmap</strong>, can be used.
|
393 | 395 | Secondly, changes in colors should be accessible to the largest number of people.
|
394 |
| -Therefore, it is important to use colorblind friendly palettes as often as possible.<a href="references.html#fn44" class="footnote-ref" id="fnref44"><sup>44</sup></a></p> |
| 396 | +Therefore, it is important to use colorblind friendly palettes as often as possible.<a class="footnote-ref" tabindex="0" data-toggle="popover" data-content="<p>See the “Color blindness simulator” options in <code>tmaptools::palette_explorer()</code>.</p>"><sup>44</sup></a></p> |
395 | 397 | </div>
|
396 | 398 | <div id="layouts" class="section level3" number="9.2.5">
|
397 | 399 | <h3>
|
|
798 | 800 | <code>shiny-server</code> also serves apps defined by a single <code>app.R</code> file in an ‘app folder’.
|
799 | 801 | Learn more at: <a href="https://github.com/rstudio/shiny-server" class="uri">https://github.com/rstudio/shiny-server</a>.
|
800 | 802 | </div>
|
801 |
| -<p>Before considering large apps, it is worth seeing a minimal example, named ‘lifeApp’, in action.<a href="references.html#fn45" class="footnote-ref" id="fnref45"><sup>45</sup></a> |
| 803 | +<p>Before considering large apps, it is worth seeing a minimal example, named ‘lifeApp’, in action.<a class="footnote-ref" tabindex="0" data-toggle="popover" data-content="<p> |
| 804 | +The word ‘app’ in this context refers to ‘web application’ and should not be confused with smartphone apps, the more common meaning of the word.</p>"><sup>45</sup></a> |
802 | 805 | The code below defines and launches — with the command <code><a href="https://rdrr.io/pkg/shiny/man/shinyApp.html">shinyApp()</a></code> — a lifeApp, which provides an interactive slider allowing users to make countries appear with progressively lower levels of life expectancy (see Figure <a href="adv-map.html#fig:lifeApp">9.24</a>):</p>
|
803 | 806 | <div class="sourceCode" id="cb329"><pre class="downlit sourceCode r">
|
804 | 807 | <code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://shiny.rstudio.com/">shiny</a></span><span class="op">)</span> <span class="co"># for shiny apps</span>
|
@@ -1189,6 +1192,7 @@ <h2>
|
1189 | 1192 | </ol>
|
1190 | 1193 | </div>
|
1191 | 1194 | </div>
|
| 1195 | + |
1192 | 1196 | <div class="chapter-nav">
|
1193 | 1197 | <div class="prev"><a href="read-write.html"><span class="header-section-number">8</span> Geographic data I/O</a></div>
|
1194 | 1198 | <div class="next"><a href="gis.html"><span class="header-section-number">10</span> Bridges to GIS software</a></div>
|
@@ -1241,7 +1245,7 @@ <h2>Note: Second Edition is under construction 🏗</h2>
|
1241 | 1245 | <footer class="bg-primary text-light mt-5"><div class="container"><div class="row">
|
1242 | 1246 |
|
1243 | 1247 | <div class="col-12 col-md-6 mt-3">
|
1244 |
| - <p>"<strong>Geocomputation with R</strong>" was written by Robin Lovelace, Jakub Nowosad, Jannes Muenchow. It was last built on 2022-03-17.</p> |
| 1248 | + <p>"<strong>Geocomputation with R</strong>" was written by Robin Lovelace, Jakub Nowosad, Jannes Muenchow. It was last built on 2022-03-18.</p> |
1245 | 1249 | </div>
|
1246 | 1250 |
|
1247 | 1251 | <div class="col-12 col-md-6 mt-3">
|
|
0 commit comments