Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
update spatial and project descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam M. Wilson committed Oct 3, 2016
1 parent 926db75 commit 2b7ea19
Show file tree
Hide file tree
Showing 59 changed files with 135 additions and 109 deletions.
4 changes: 2 additions & 2 deletions 00_CourseIntroductionFrame.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@
<li class="divider"></li>
<li class="dropdown-header">Module 2: Spatial Analyses</li>
<li>
<a href="04_Spatial.html">Spatial Data</a>
<a href="04_Spatial.html">04 Spatial Data</a>
</li>
<li>
<a href="05_Raster.html">Spatial Raster Data</a>
<a href="05_Raster.html">05 Spatial Raster Data</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Module 2: Advanced Programming</li>
Expand Down
4 changes: 2 additions & 2 deletions 01_Rintro.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@
<li class="divider"></li>
<li class="dropdown-header">Module 2: Spatial Analyses</li>
<li>
<a href="04_Spatial.html">Spatial Data</a>
<a href="04_Spatial.html">04 Spatial Data</a>
</li>
<li>
<a href="05_Raster.html">Spatial Raster Data</a>
<a href="05_Raster.html">05 Spatial Raster Data</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Module 2: Advanced Programming</li>
Expand Down
4 changes: 2 additions & 2 deletions 02_DataWrangling.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@
<li class="divider"></li>
<li class="dropdown-header">Module 2: Spatial Analyses</li>
<li>
<a href="04_Spatial.html">Spatial Data</a>
<a href="04_Spatial.html">04 Spatial Data</a>
</li>
<li>
<a href="05_Raster.html">Spatial Raster Data</a>
<a href="05_Raster.html">05 Spatial Raster Data</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Module 2: Advanced Programming</li>
Expand Down
4 changes: 2 additions & 2 deletions 03_Plotting.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@
<li class="divider"></li>
<li class="dropdown-header">Module 2: Spatial Analyses</li>
<li>
<a href="04_Spatial.html">Spatial Data</a>
<a href="04_Spatial.html">04 Spatial Data</a>
</li>
<li>
<a href="05_Raster.html">Spatial Raster Data</a>
<a href="05_Raster.html">05 Spatial Raster Data</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Module 2: Advanced Programming</li>
Expand Down
12 changes: 9 additions & 3 deletions 05_Spatial.R → 04_Spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' ---
#'
#'
#' This file is available as a [<i class="fa fa-file-text" aria-hidden="true"></i> R script here](`r output`). Download this file and open it (or copy-paste into a new script) with RStudio so you can follow along.
#' [<i class="fa fa-file-code-o fa-3x" aria-hidden="true"></i> The R Script associated with this page is available here](`r output`). Download this file and open it (or copy-paste into a new script) with RStudio so you can follow along.
#'
#' # Setup
#'
Expand Down Expand Up @@ -115,10 +115,16 @@ data(meuse)
str(meuse)

#'
#'
#' <div class="well">
#' ## Your turn
#' _Promote_ the `meuse` object to a spatial points data.frame with `coordinates()`.
#'
#' <button data-toggle="collapse" class="btn btn-primary btn-sm round" data-target="#demo2">Show Solution</button>
#' <div id="demo2" class="collapse">
#'
#'
#' </div>
#' </div>
#'
#' Plot it with ggplot:
## ---- fig.height=4-------------------------------------------------------
Expand Down Expand Up @@ -183,7 +189,7 @@ str(SLDF)
#'
#' ## Getting complicated
#'
#' <img src="assets/polygons.png" alt="alt text" width="75%">
#' <img src="05_assets/polygons.png" alt="alt text" width="75%">
#'
#' ### Issues
#'
Expand Down
12 changes: 9 additions & 3 deletions 05_Spatial.Rmd → 04_Spatial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ knitr::purl(input,output,documentation=2,quiet=T)
source("knitr_header.R")
```

This file is available as a [<i class="fa fa-file-text" aria-hidden="true"></i> R script here](`r output`). Download this file and open it (or copy-paste into a new script) with RStudio so you can follow along.
[<i class="fa fa-file-code-o fa-3x" aria-hidden="true"></i> The R Script associated with this page is available here](`r output`). Download this file and open it (or copy-paste into a new script) with RStudio so you can follow along.

# Setup

Expand Down Expand Up @@ -129,17 +129,23 @@ data(meuse)
str(meuse)
```


<div class="well">
## Your turn
_Promote_ the `meuse` object to a spatial points data.frame with `coordinates()`.

<button data-toggle="collapse" class="btn btn-primary btn-sm round" data-target="#demo2">Show Solution</button>
<div id="demo2" class="collapse">

```{r,purl=F}
coordinates(meuse) <- ~x+y
# OR coordinates(meuse)=cbind(meuse$x,meuse$y)
# OR coordinates(meuse))=c("x","y")
str(meuse)
```

</div>
</div>

Plot it with ggplot:
```{r, fig.height=4}
ggplot(as.data.frame(meuse),aes(x=x,y=y))+
Expand Down Expand Up @@ -203,7 +209,7 @@ str(SLDF)

## Getting complicated

<img src="assets/polygons.png" alt="alt text" width="75%">
<img src="05_assets/polygons.png" alt="alt text" width="75%">

### Issues

Expand Down
47 changes: 26 additions & 21 deletions 05_Spatial.html → 04_Spatial.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@
<li class="divider"></li>
<li class="dropdown-header">Module 2: Spatial Analyses</li>
<li>
<a href="04_Spatial.html">Spatial Data</a>
<a href="04_Spatial.html">04 Spatial Data</a>
</li>
<li>
<a href="05_Raster.html">Spatial Raster Data</a>
<a href="05_Raster.html">05 Spatial Raster Data</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Module 2: Advanced Programming</li>
Expand Down Expand Up @@ -360,7 +360,7 @@ <h1 class="title">Working with Spatial Data</h1>
</div>


<p>This file is available as a <a href="05_Spatial.R"><i class="fa fa-file-text" aria-hidden="true"></i> R script here</a>. Download this file and open it (or copy-paste into a new script) with RStudio so you can follow along.</p>
<p><a href="04_Spatial.R"><i class="fa fa-file-code-o fa-3x" aria-hidden="true"></i> The R Script associated with this page is available here</a>. Download this file and open it (or copy-paste into a new script) with RStudio so you can follow along.</p>
<div id="setup" class="section level1">
<h1>Setup</h1>
<div id="load-packages" class="section level2">
Expand All @@ -386,7 +386,7 @@ <h2>Generate some random data</h2>
## $ x: num -0.7755 1.5926 1.038 -0.0797 -1.6608 ...
## $ y: num -0.0159 0.7206 0.08 0.7659 0.5246 ...</code></pre>
<pre class="r"><code>plot(coords)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-4-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-4-1.png" alt="" /><!-- --></p>
</div>
<div id="convert-to-spatialpoints" class="section level2">
<h2>Convert to <code>SpatialPoints</code></h2>
Expand Down Expand Up @@ -520,7 +520,7 @@ <h2 id="your-turn">Your turn</h2>
<div id="demo1" class="collapse">
<pre class="r"><code>coordinates(df)=c(&quot;lon&quot;,&quot;lat&quot;)
plot(df)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-14-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-14-1.png" alt="" /><!-- --></p>
</div>
</div>
</div>
Expand All @@ -544,10 +544,13 @@ <h2>Examine topsoil quality in the Meuse river data set</h2>
## $ lime : Factor w/ 2 levels &quot;0&quot;,&quot;1&quot;: 2 2 2 1 1 1 1 1 1 1 ...
## $ landuse: Factor w/ 15 levels &quot;Aa&quot;,&quot;Ab&quot;,&quot;Ag&quot;,..: 4 4 4 11 4 11 4 2 2 15 ...
## $ dist.m : num 50 30 150 270 380 470 240 120 240 420 ...</code></pre>
</div>
<div id="your-turn-1" class="section level2">
<h2>Your turn</h2>
<div class="well">
<h2 id="your-turn-1">Your turn</h2>
<p><em>Promote</em> the <code>meuse</code> object to a spatial points data.frame with <code>coordinates()</code>.</p>
<button data-toggle="collapse" class="btn btn-primary btn-sm round" data-target="#demo2">
Show Solution
</button>
<div id="demo2" class="collapse">
<pre class="r"><code>coordinates(meuse) &lt;- ~x+y
# OR coordinates(meuse)=cbind(meuse$x,meuse$y)
# OR coordinates(meuse))=c(&quot;x&quot;,&quot;y&quot;)
Expand Down Expand Up @@ -577,11 +580,13 @@ <h2>Your turn</h2>
## .. .. ..$ : chr [1:2] &quot;min&quot; &quot;max&quot;
## ..@ proj4string:Formal class &#39;CRS&#39; [package &quot;sp&quot;] with 1 slot
## .. .. ..@ projargs: chr NA</code></pre>
</div>
</div>
<p>Plot it with ggplot:</p>
<pre class="r"><code> ggplot(as.data.frame(meuse),aes(x=x,y=y))+
geom_point(col=&quot;red&quot;)+
coord_equal()</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-17-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-17-1.png" alt="" /><!-- --></p>
<p>Note that <code>ggplot</code> works only with data.frames. Convert with <code>as.data.frame()</code> or <code>fortify()</code>.</p>
</div>
</div>
Expand All @@ -602,7 +607,7 @@ <h3>A <code>Line</code> is a single chain of points.</h3>
## [4,] -0.0470298 -1.2565673
## [5,] 0.4880012 0.3211727</code></pre>
<pre class="r"><code>plot(coordinates(L1),type=&quot;l&quot;)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-19-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-19-1.png" alt="" /><!-- --></p>
</div>
<div id="a-lines-object-is-a-list-of-chains-with-an-id" class="section level3">
<h3>A <code>Lines</code> object is a list of chains with an ID</h3>
Expand Down Expand Up @@ -641,7 +646,7 @@ <h3>A <code>Lines</code> object is a list of chains with an ID</h3>
<h3>A <code>SpatialLines</code> is a list of Lines</h3>
<pre class="r"><code>SL12 = SpatialLines(list(Ls1,Ls2))
plot(SL12)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-21-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-21-1.png" alt="" /><!-- --></p>
</div>
<div id="a-spatiallinesdataframe-is-a-spatiallines-with-a-matching-dataframe" class="section level3">
<h3>A <code>SpatialLinesDataFrame</code> is a <code>SpatialLines</code> with a matching <code>DataFrame</code></h3>
Expand Down Expand Up @@ -680,7 +685,7 @@ <h3>A <code>SpatialLinesDataFrame</code> is a <code>SpatialLines</code> with a m
<h1>Polygons</h1>
<div id="getting-complicated" class="section level2">
<h2>Getting complicated</h2>
<p><img src="assets/polygons.png" alt="alt text" width="75%"></p>
<p><img src="05_assets/polygons.png" alt="alt text" width="75%"></p>
<div id="issues" class="section level3">
<h3>Issues</h3>
<ul>
Expand Down Expand Up @@ -1003,7 +1008,7 @@ <h2>Geospatial Data Abstraction Library (<a href="gdal.org">GDAL</a>)</h2>
## Max. :57.00 Max. :11631.0
## </code></pre>
<pre class="r"><code>plot(sids)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-24-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-24-1.png" alt="" /><!-- --></p>
<div id="maptools-package" class="section level3">
<h3>Maptools package</h3>
<p>The <code>maptools</code> package has an alternative function for importing shapefiles that can be a little easier to use (but has fewer options).</p>
Expand Down Expand Up @@ -1069,14 +1074,14 @@ <h2>Spatial Transform</h2>
geom_polygon(fill=&quot;white&quot;,col=&quot;black&quot;)+
coord_equal()</code></pre>
<pre><code>## Regions defined for each Polygons</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-29-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-29-1.png" alt="" /><!-- --></p>
<pre class="r"><code># Equal Area
ggplot(fortify(sids_us),aes(x=long,y=lat,order=order,group=group))+
geom_polygon(fill=&quot;white&quot;,col=&quot;black&quot;)+
coord_equal()+
ylab(&quot;Northing&quot;)+xlab(&quot;Easting&quot;)</code></pre>
<pre><code>## Regions defined for each Polygons</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-29-2.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-29-2.png" alt="" /><!-- --></p>
</div>
</div>
<div id="rgeos" class="section level1">
Expand Down Expand Up @@ -1108,7 +1113,7 @@ <h3>Simplication of lines</h3>
plot(gSimplify(l,tol=3));title(&quot;tol: 3&quot;)
plot(gSimplify(l,tol=5));title(&quot;tol: 5&quot;)
plot(gSimplify(l,tol=7));title(&quot;tol: 7&quot;)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-32-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-32-1.png" alt="" /><!-- --></p>
</div>
<div id="simplification-of-polygons" class="section level3">
<h3>Simplification of polygons</h3>
Expand All @@ -1117,7 +1122,7 @@ <h3>Simplification of polygons</h3>
plot(gSimplify(p,tol=10));title(&quot;tol: 10&quot;)
plot(gSimplify(p,tol=20));title(&quot;tol: 20&quot;)
plot(gSimplify(p,tol=25));title(&quot;tol: 25&quot;)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-33-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-33-1.png" alt="" /><!-- --></p>
</div>
</div>
<div id="use-rgeos-functions-with-real-spatial-data" class="section level2">
Expand Down Expand Up @@ -1152,14 +1157,14 @@ <h3>Plotting vectors with ggplot</h3>
geom_polygon(lwd=2,fill=&quot;grey&quot;,col=&quot;blue&quot;)+
coord_map()</code></pre>
<pre><code>## Regions defined for each Polygons</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-37-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-37-1.png" alt="" /><!-- --></p>
<p>Now let’s overlay the simplified version to see how they differ.</p>
<pre class="r"><code>ggplot(fortify(sids),aes(x=long,y=lat,order=order, group=group))+
geom_polygon(lwd=2,fill=&quot;grey&quot;,col=&quot;blue&quot;)+
geom_polygon(data=fortify(sids2),col=&quot;red&quot;,fill=NA)+
coord_map()</code></pre>
<pre><code>## Regions defined for each Polygons</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-38-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-38-1.png" alt="" /><!-- --></p>
<p>How does changing the tolerance (<code>tol</code>) affect the map?</p>
</div>
</div>
Expand All @@ -1183,7 +1188,7 @@ <h3>Plot a chloropleth of area</h3>
scale_fill_gradientn(colours = c(&quot;grey&quot;,&quot;goldenrod&quot;,&quot;darkgreen&quot;,&quot;green&quot;))+
coord_map()+
geom_map(aes(fill = area), map = fsids)</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-40-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-40-1.png" alt="" /><!-- --></p>
</div>
</div>
<div id="union" class="section level2">
Expand All @@ -1193,7 +1198,7 @@ <h2>Union</h2>
<pre class="r"><code>ggplot(fortify(sids_all),aes(x=long,y=lat,group=group,order=order))+
geom_path()+
coord_map()</code></pre>
<p><img src="05_Spatial_files/figure-html/unnamed-chunk-42-1.png" alt="" /><!-- --></p>
<p><img src="04_Spatial_files/figure-html/unnamed-chunk-42-1.png" alt="" /><!-- --></p>
</div>
<div id="colophon" class="section level2">
<h2>Colophon</h2>
Expand Down
Loading

0 comments on commit 2b7ea19

Please sign in to comment.