/
v06_plotting.html
223 lines (196 loc) · 18.9 KB
/
v06_plotting.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="finbif">
<title>Plotting FinBIF data • finbif</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<script src="../deps/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">
<link href="../deps/bootstrap-5.1.0/bootstrap.min.css" rel="stylesheet">
<script src="../deps/bootstrap-5.1.0/bootstrap.bundle.min.js"></script><link href="../deps/_Roboto-0.4.0/font.css" rel="stylesheet">
<!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- bootstrap-toc --><script src="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.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><!-- search --><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://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
<meta property="og:title" content="Plotting FinBIF data">
<meta property="og:description" content="finbif">
<meta property="og:image" content="/logo.png">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
<a class="navbar-brand me-2" href="../index.html">finbif</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">0.6.2.9002</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-2">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="../articles/finbif.html">Get started</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../reference/index.html">Reference</a>
</li>
<li class="active nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown-articles">Articles</a>
<div class="dropdown-menu" aria-labelledby="dropdown-articles">
<a class="dropdown-item" href="../articles/v02_occurrence_data.html">Occurrence records from FinBIF</a>
<a class="dropdown-item" href="../articles/v03_selecting_variables.html">Selecting and ordering variables</a>
<a class="dropdown-item" href="../articles/v04_metadata.html">Metadata</a>
<a class="dropdown-item" href="../articles/v05_filtering.html">Filtering occurrence records</a>
<a class="dropdown-item" href="../articles/v06_plotting.html">Plotting FinBIF data</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="../news/index.html">Changelog</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0" role="search">
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
</form>
<ul class="navbar-nav">
<li class="nav-item">
<a class="external-link nav-link" href="https://github.com/luomus/finbif/" aria-label="github">
<span class="fab fa fab fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
</div>
</nav><div class="container template-article">
<div class="row">
<main id="main"><div class="page-header">
<img src="../logo.png" class="logo" alt=""><h1>Plotting FinBIF data</h1>
<h4 data-toc-skip class="author">William K. Morris</h4>
<small class="dont-index">Source: <a href="https://github.com/luomus/finbif/blob/HEAD/vignettes/v06_plotting.Rmd" class="external-link"><code>vignettes/v06_plotting.Rmd</code></a></small>
<div class="d-none name"><code>v06_plotting.Rmd</code></div>
</div>
<p>Visualisation is an important part of data exploration and analysis. The <a href="https://github.com/luomus/finbif" class="external-link">finbif</a> package has a few functions and methods that can be used to visualise occurrence data from FinBIF.</p>
<div class="section level2">
<h2 id="occurrence-points">Occurrence points<a class="anchor" aria-label="anchor" href="#occurrence-points"></a>
</h2>
<p>The default <code><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot()</a></code> method for the result of a call to <code><a href="../reference/finbif_occurrence.html">finbif_occurrence()</a></code> will display (if available) coordinates of the occurrence points in a scatter-plot.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">recent_obs</span> <span class="op"><-</span> <span class="fu"><a href="../reference/finbif_occurrence.html">finbif_occurrence</a></span><span class="op">(</span>filter <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span>country <span class="op">=</span> <span class="st">"Finland"</span><span class="op">)</span>, n <span class="op">=</span> <span class="fl">1000</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">recent_obs</span><span class="op">)</span></code></pre></div>
<p><img src="../reference/figures/plot-recent-obs-1.png"></p>
</div>
<div class="section level2">
<h2 id="occurrence-density">Occurrence density<a class="anchor" aria-label="anchor" href="#occurrence-density"></a>
</h2>
<p>When you have many points to visualise it may be beneficial to display them in a 2-dimensional histogram with the density of points indicated by the shading or colour of filled grid-cells. The following outlines how this can be achieved using some tools provided by <a href="https://github.com/luomus/finbif" class="external-link">finbif</a>.</p>
<div class="section level3">
<h3 id="data">Data<a class="anchor" aria-label="anchor" href="#data"></a>
</h3>
<p>First you’ll need to acquire some occurrence records. For example, you can use the following to get the latitude and longitude of all the Finnish records of Eurasian Jays where the coordinate uncertainty is less then 100m<a class="footnote-ref" tabindex="0" data-bs-toggle="popover" data-bs-content="<p>Or the coordinate uncertainty has not been specified.</p>"><sup>1</sup></a>.</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">jays</span> <span class="op"><-</span> <span class="fu"><a href="../reference/finbif_occurrence.html">finbif_occurrence</a></span><span class="op">(</span>
<span class="st">"Eurasian Jay"</span>,
filter <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span>coordinates_uncertainty_max <span class="op">=</span> <span class="fl">100</span>, country <span class="op">=</span> <span class="st">"Finland"</span><span class="op">)</span>,
select <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"lon_wgs84"</span>, <span class="st">"lat_wgs84"</span><span class="op">)</span>,
n <span class="op">=</span> <span class="fl">2e4</span>
<span class="op">)</span></code></pre></div>
</div>
<div class="section level3">
<h3 id="breakpoints">Breakpoints<a class="anchor" aria-label="anchor" href="#breakpoints"></a>
</h3>
<p>Now you will need to define the break points of the grid cells over which to plot the density of occurrence records.</p>
<p>The <a href="https://github.com/luomus/finbif" class="external-link">finbif</a> package has an inbuilt Finland map object which includes its bounding box.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">finland_map</span><span class="op">$</span><span class="va">bbox</span>
<span class="co">#> [1] 19 59 32 71</span></code></pre></div>
<p>You can use the function <code>breaks_xy</code> in combination with map bounding box to compute break points that a quarter of a degree in both dimensions.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="op">(</span><span class="va">breaks</span> <span class="op"><-</span> <span class="fu"><a href="../reference/breaks_xy.html">breaks_xy</a></span><span class="op">(</span><span class="va">finland_map</span><span class="op">$</span><span class="va">bbox</span>, size <span class="op">=</span> <span class="fl">.25</span><span class="op">)</span><span class="op">)</span>
<span class="co">#> $x</span>
<span class="co">#> [1] 19.00 19.25 19.50 19.75 20.00 20.25 20.50 20.75 21.00 21.25 21.50 21.75 22.00 22.25 22.50 22.75</span>
<span class="co">#> [17] 23.00 23.25 23.50 23.75 24.00 24.25 24.50 24.75 25.00 25.25 25.50 25.75 26.00 26.25 26.50 26.75</span>
<span class="co">#> [33] 27.00 27.25 27.50 27.75 28.00 28.25 28.50 28.75 29.00 29.25 29.50 29.75 30.00 30.25 30.50 30.75</span>
<span class="co">#> [49] 31.00 31.25 31.50 31.75 32.00</span>
<span class="co">#> </span>
<span class="co">#> $y</span>
<span class="co">#> [1] 59.00 59.25 59.50 59.75 60.00 60.25 60.50 60.75 61.00 61.25 61.50 61.75 62.00 62.25 62.50 62.75</span>
<span class="co">#> [17] 63.00 63.25 63.50 63.75 64.00 64.25 64.50 64.75 65.00 65.25 65.50 65.75 66.00 66.25 66.50 66.75</span>
<span class="co">#> [33] 67.00 67.25 67.50 67.75 68.00 68.25 68.50 68.75 69.00 69.25 69.50 69.75 70.00 70.25 70.50 70.75</span>
<span class="co">#> [49] 71.00</span></code></pre></div>
</div>
<div class="section level3">
<h3 id="d-histogram">2d histogram<a class="anchor" aria-label="anchor" href="#d-histogram"></a>
</h3>
<p>The function <code>hist_xy</code> can be used compute the density of occurrences in the grid-cells defined by a set of break points.</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">jay_density</span> <span class="op"><-</span> <span class="fu"><a href="../reference/hist_xy.html">hist_xy</a></span><span class="op">(</span><span class="va">jays</span>, <span class="va">breaks</span><span class="op">)</span></code></pre></div>
</div>
<div class="section level3">
<h3 id="image">Image<a class="anchor" aria-label="anchor" href="#image"></a>
</h3>
<p>The function <code><a href="https://rdrr.io/r/graphics/image.html" class="external-link">image()</a></code> creates a grid of colored rectangles with colors corresponding to the density of occurrence records. You can use its arguments to control properties of the plot such as the aspect ratio<a class="footnote-ref" tabindex="0" data-bs-toggle="popover" data-bs-content="<p>An aspect ratio of 2.4 minimizes the distortion of displaying Finland in a unprojected coordinate system.</p>"><sup>2</sup></a>, the breaks<a class="footnote-ref" tabindex="0" data-bs-toggle="popover" data-bs-content="<p>Note that this is different from the break points for the grid cells. This <code>breaks</code> argument defines the break points for the grid cell colors.</p>"><sup>3</sup></a>, the color palette, the axis labels and grid lines.</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/graphics/image.html" class="external-link">image</a></span><span class="op">(</span>
<span class="va">jay_density</span>,
asp <span class="op">=</span> <span class="fl">2.4</span>,
breaks <span class="op">=</span> <span class="fl">2</span><span class="op">^</span><span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">12</span><span class="op">)</span>,
col <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/grDevices/palettes.html" class="external-link">hcl.colors</a></span><span class="op">(</span><span class="fl">12</span>, rev <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>,
xlab <span class="op">=</span> <span class="st">"Longitude"</span>,
ylab <span class="op">=</span> <span class="st">"Latitude"</span>,
las <span class="op">=</span> <span class="fl">1</span>,
panel.first <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/graphics/grid.html" class="external-link">grid</a></span><span class="op">(</span><span class="op">)</span>
<span class="op">)</span></code></pre></div>
</div>
<div class="section level3">
<h3 id="legend">Legend<a class="anchor" aria-label="anchor" href="#legend"></a>
</h3>
<p>You can add a plot legend to indicate how the image breakpoints are mapped to the image colors.</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/graphics/legend.html" class="external-link">legend</a></span><span class="op">(</span>
<span class="st">"topright"</span>,
inset <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">.01</span><span class="op">)</span>,
legend <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/expression.html" class="external-link">expression</a></span><span class="op">(</span><span class="fl">2</span><span class="op">^</span><span class="fl">12</span>, <span class="st">""</span>, <span class="st">""</span>, <span class="fl">2</span><span class="op">^</span><span class="fl">6</span>, <span class="st">""</span>, <span class="st">""</span>, <span class="fl">2</span><span class="op">^</span><span class="fl">0</span><span class="op">)</span>,
fill <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/grDevices/palettes.html" class="external-link">hcl.colors</a></span><span class="op">(</span><span class="fl">7</span><span class="op">)</span>,
border <span class="op">=</span> <span class="cn">NA</span>,
bty <span class="op">=</span> <span class="st">"n"</span>,
adj <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">0.25</span><span class="op">)</span>,
x.intersp <span class="op">=</span> <span class="fl">.2</span>,
y.intersp <span class="op">=</span> <span class="fl">.5</span>
<span class="op">)</span></code></pre></div>
</div>
<div class="section level3">
<h3 id="border">Border<a class="anchor" aria-label="anchor" href="#border"></a>
</h3>
<p>Finally, you can use <a href="https://github.com/luomus/finbif" class="external-link">finbif</a>’s internal map to add the border of Finland to your plot.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/graphics/polygon.html" class="external-link">polygon</a></span><span class="op">(</span><span class="va">finland_map</span><span class="op">$</span><span class="va">vertices</span>, lwd <span class="op">=</span> <span class="fl">.2</span><span class="op">)</span></code></pre></div>
<p><img src="../reference/figures/plot-finland-1.png"></p>
</div>
</div>
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
</nav></aside>
</div>
<footer><div class="pkgdown-footer-left">
<p></p>
<p>Developed by William K. Morris.</p>
</div>
<div class="pkgdown-footer-left">
<p><a class="external-link" href="https://www.netlify.com"><img src="https://www.netlify.com/img/global/badges/netlify-light.svg" alt="Deploys by Netlify"></a></p>
</div>
<div class="pkgdown-footer-right">
<p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.0.</p>
</div>
</footer>
</div>
</body>
</html>