Skip to content

Commit

Permalink
Deploy commit: Merge pull request #689 from Robinlovelace/Robinlovela…
Browse files Browse the repository at this point in the history
…ce-patch-1

Update 02-spatial-data.Rmd 83a5f27
  • Loading branch information
Nowosad committed Dec 14, 2021
1 parent 68433e3 commit 789ebc1
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 92 deletions.
10 changes: 6 additions & 4 deletions 02-spatial-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,13 @@ Consequently, the discrete borders of these features become blurred, and dependi
<p class="caption">(\#fig:raster-intro-plot2)Examples of continuous and categorical rasters.</p>
</div>

### R packages for raster data handling
### R packages for working with raster data

R has several packages able to read and process spatial raster data; see \Wref(the-history-of-r-spatial) for more context.
However, currently, two main packages with this purpose exist -- **terra** and **stars**.^[We are not mentioning the **raster** package here as it is now being replaced with **terra**.]
We are focusing on the **terra** package in this book; however, it may be worth knowing the basic similarities and differences between the packages before deciding which one to use.
Over the last two decades, several packages packages for reading and processing raster datasets have been developed.
As outlined in Section \@ref(the-history-of-r-spatial), chief among them was **raster**, which led to a step change in R's raster capabilities when it was launched in 2010 and the premier package in the space until the development of **terra** and **stars**.
Both more recently developed package provide powerful and performant functions for working with raster datasets and there is substantial overlap between their possibly use cases.
In this book we focus on **terra**, which replaces the older and (in most cases) slower **raster**.
Before learning about the how **terra**'s class system works, this section describes similarities and differences between **terra** and **raster**; this knowledge will help decide which is most appropriate in different situations.

First, **terra** focuses on the most common raster data model (regular grids), while **stars** also allows storing less popular models (including regular, rotated, sheared, rectilinear, and curvilinear grids).
While **terra** usually handle one or multi-layered rasters^[It also has an additional class `SpatRasterDataset` for storing many collections of datasets.], the **stars** package provides ways to store raster data cubes -- a raster object with many layers (e.g., bands), for many moments in time (e.g., months), and many attributes (e.g., sensor type A and sensor type B).
Expand Down
8 changes: 4 additions & 4 deletions adv-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ <h3>
<p>There are two main types of map aesthetics: those that change with the data and those that are constant.
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.
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="&lt;p&gt;
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 &lt;code&gt;nz$red = 1:nrow(nz)&lt;/code&gt;.&lt;/p&gt;"><sup>40</sup></a>
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 &lt;code&gt;nz$red = 1:nrow(nz)&lt;/code&gt;.&lt;/p&gt;"><sup>39</sup></a>
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.
The impact of setting these with fixed values is illustrated in Figure <a href="adv-map.html#fig:tmstatic">8.3</a>.</p>
<div class="sourceCode" id="cb268"><pre class="downlit sourceCode r">
Expand Down Expand Up @@ -368,7 +368,7 @@ <h3>
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.
Colors should be intuitive: rivers should be blue, for example, and pastures green.
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='&lt;p&gt;
&lt;code&gt;col = "MAP_COLORS"&lt;/code&gt; 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.&lt;/p&gt;'><sup>41</sup></a></p>
&lt;code&gt;col = "MAP_COLORS"&lt;/code&gt; 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.&lt;/p&gt;'><sup>40</sup></a></p>
<p>The second group is sequential palettes.
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.
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>
Expand All @@ -393,7 +393,7 @@ <h3>
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>.
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.
Secondly, changes in colors should be accessible to the largest number of people.
Therefore, it is important to use colorblind friendly palettes as often as possible.<a class="footnote-ref" tabindex="0" data-toggle="popover" data-content="&lt;p&gt;See the “Color blindness simulator” options in &lt;code&gt;tmaptools::palette_explorer()&lt;/code&gt;.&lt;/p&gt;"><sup>42</sup></a></p>
Therefore, it is important to use colorblind friendly palettes as often as possible.<a class="footnote-ref" tabindex="0" data-toggle="popover" data-content="&lt;p&gt;See the “Color blindness simulator” options in &lt;code&gt;tmaptools::palette_explorer()&lt;/code&gt;.&lt;/p&gt;"><sup>41</sup></a></p>
</div>
<div id="layouts" class="section level3" number="8.2.5">
<h3>
Expand Down Expand Up @@ -801,7 +801,7 @@ <h2>
Learn more at: <a href="https://github.com/rstudio/shiny-server" class="uri">https://github.com/rstudio/shiny-server</a>.
</div>
<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="&lt;p&gt;
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.&lt;/p&gt;"><sup>43</sup></a>
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.&lt;/p&gt;"><sup>42</sup></a>
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">8.24</a>):</p>
<div class="sourceCode" id="cb295"><pre class="downlit sourceCode r">
<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>
Expand Down
Loading

0 comments on commit 789ebc1

Please sign in to comment.