Spatial Data in R


Welcome to Week 4!

Welcome to week 4 of Earth Analytics! This week, you will dive deeper into working with spatial data in R. You will learn how to handle data in different coordinate reference systems, how to create custom maps and legends and how to extract data from a raster file. You are on your way towards integrating many different types of data into your analysis which involves knowing how to deal with things like coordinate reference systems and varying data structures.

What You Need

You will need a computer with internet access to complete this lesson and the data for week 4 of the course. Note that the data download below is large (500MB) however it contains data that you will use for the next 2 weeks!

Download Week 4 Data (~500 MB)

TimeTopicSpeaker  
9:30 AMQuestions / RLeah  
9:45 - 10:15Coordinate reference systems & spatial metadata 101   
10:25 - 12:20R coding session - spatial data in RLeah  

1. Complete the Assignment Below

Homework (5 points): Due Monday Oct 2 @ 8AM

Produce a Report

Create a new R markdown document. Name it: lastName-firstInitial-week4.Rmd Within your .Rmd document, include the plots listed below.

When you are done with your report, use knitr to convert it to .html format (note: if you did not get knitr working it is ok if you create an html document and export it to pdf as demonstrated in class). You will submit both the .Rmd file and the .html file. Be sure to name your files as instructed above!

In your report, include the plots below. The important part of this week is that you document each step of your workflow using comments. And that you break up the sections of your analysis into SEPARATE code chunks.

Answer the Questions Below in Your Report

Write 1 paragraph addressing the following:

  1. In your own words, define what a Coordinate Reference System (CRS) is.
  2. What are the key components that make up a CRS?
  3. If you are working with two datasets that are stored using difference CRSs, and want to process or plot them, what do you need to do to ensure that they line up on a map and can be processed together?
  4. In R, how do you check to see if two datasets are in the same CRS?

Plot 1 - Roads Map and Legend

Create a map of California roads:

  1. Import the madera-county-roads/tl_2013_06039_roads.shp layer located in your week_04 data download.
  2. Create a map that shows the madera roads layer, sjer plot locations and the sjer_aoi boundary (sjer_crop.shp).
  3. Plot the roads so different road types are represented using unique symbology.
  4. Map the plot locations by the attribute plot type using unique symbology for each “type”.
  5. Add a title to your plot.
  6. Adjust your plot legend.

IMPORTANT: be sure that all of the data are within the same EXTENT and crs of the sjer_aoi layer. This means that you may have to crop and reproject your data prior to plotting it!

Be sure that your plot legend is not covering your data. Use the homework lesson on base plot legends to help build the legend. Or use ggplot to create your plot.

BONUS 1 (.5 points): Use colorBrewer to Create a Color Ramp

In the lessons, I show you how to color your map by manually selecting colors. Use the RColorBrewer package to create a set of colors to use on your plot.

BONUS 2 (.5 points): Use mapView or leaflet to create an interactive map with popups.

This tutorial may help you get started.

Submit to D2L

Submit your report in both .Rmd and .html format to the D2l week 4 dropbox by 8am. NOTE: it is OK if you’d like to submit an pdf document to D2l but pdf’s won’t support interactive maps!

.html Report Structure & Code: 20%

Full CreditNo Credit 
.html and RMD submitted  
Code is written using “clean” code practices following the Hadley Wickham style guide  
YAML contains a title, author and date  
Rmd code chunks contains code and runs  
All required R packages are listed at the top of the document in a code chunk.  

Knitr pdf Output: 10%

Full CreditNo Credit
Code chunk arguments are used to hide warnings 
Code chunk arguments are used to hide code and just show output 
.html report emphasizes the write up and the code outputs rather than showing each step of the code 

PLOT: Map of Madera County with Roads 40%

Full CreditNo Credit 
Roads, plot locations & AOI boundary are included on the map  
Road lines are symbolized by type  
Plot location points are symbolized by type  
Plots has a title that clearly defines plot contents  
Plots have a 2-3 sentence caption that clearly describes plot contents  
Plot legend is next to the map (on the side or below) and doesn’t overlay the plot contents  
Plot legend is formatted with the correctly symbology that matches the map and is easy to read  

Report Questions: 30%

Full CreditNo Credit
In your own words, define what a Coordinate Reference System (CRS) is 
What are the key components that make up a CRS? 
If you are working with two datasets that are stored using difference CRSs, and want to process or plot them, what do you need to do to ensure that they line up on a map and can be processed together? 
In R, how do you check to see if two datasets are in the same CRS?