Introduction to Working With Raster Data in R feature image Source: National Ecological Observatory Network (NEON)
NEON EDUCATION bio photo

NEON EDUCATION

Devoted to open data and open source in science and education.

View All Tutorials

Tags

LiDAR (7)
R programming (51)
Remote Sensing (12)
Data Visualization (4)
Hyperspectral Remote Sensing (7)
Hierarchical Data Formats (HDF5) (9)
Spatial Data & GIS (18)
Time Series (15)
Phenology (7)
Raster Data (8)
Vector Data (6)
Metadata (1)
Git & GitHub (6)
(1) (1)

Tutorial by R Package

dplyr (7)
ggplot2 (17)
h5py (1)
lubridate (time series) (6)
maps (1)
maptools (2)
plyr (2)
raster (26)
rasterVis (raster time series) (3)
rgdal (GIS) (22)
rgeos (3)
rhdf5 (11)
sp (5)
scales (4)
gridExtra (4)
ggtheme (0)
grid (2)
reshape2 (3)
plotly (5)

View ALL Tutorial Series




Twitter Youtube Github


Blog.Roll

R Bloggers

Series: Introduction to Working With Raster Data in R

About

The tutorials in this series cover how to open, work with and plot raster-format spatial data in R. Additional topics include working with spatial metadata (extent and coordinate reference system), reprojecting spatial data and working with raster time series data.

Data used in this series cover NEON Harvard Forest and San Joaquin Experimental Range field sites and are in GeoTIFF and .csv formats.

R Skill Level: Intermediate - you’ve got the basics of R down but haven’t worked with spatial data in R before.

Series Goals / Objectives

After completing the series you will:

  • Raster 00
    • Understand what a raster dataset is and its fundamental attributes.
    • Know how to explore raster attributes in R.
    • Be able to import rasters into R using the raster package.
    • Be able to quickly plot a raster file in R.
    • Understand the difference between single- and multi-band rasters.
  • Raster 01
    • Know how to plot a single band raster in R.
    • Know how to layer a raster dataset on top of a hillshade to create an elegant basemap.
  • Raster 02
    • Be able to reproject a raster in R.
  • Raster 03
    • Be able to to perform a subtraction (difference) between two rasters using raster math.
    • Know how to perform a more efficient subtraction (difference) between two rasters using the raster overlay() function in R.
  • Raster 04
    • Know how to identify a single vs. a multi-band raster file.
    • Be able to import multi-band rasters into R using the raster package.
    • Be able to plot multi-band color image rasters in R using plotRGB.
    • Understand what a NoData value is in a raster.
  • Raster 05
    • Understand the format of a time series raster dataset.
    • Know how to work with time series rasters.
    • Be able to efficiently import a set of rasters stored in a single directory.
    • Be able to plot and explore time series raster data using the plot() function in R.
  • Raster 06
    • Be able to assign custom names to bands in a RasterStack for prettier plotting.
    • Understand advanced plotting of rasters using the rasterVis package and levelplot.
  • Raster 07
    • Be able to extract summary pixel values from a raster.
    • Know how to save summary values to a .csv file.
    • Be able to plot summary pixel values using ggplot().
    • Have experience comparing NDVI values between two different sites.

Things You’ll Need To Complete This Series

Setup RStudio

To complete the tutorial series you will need an updated version of R and, preferably, RStudio installed on your computer.

R is a programming language that specializes in statistical computing. It is a powerful tool for exploratory data analysis. To interact with R, we strongly recommend RStudio, an interactive development environment (IDE).

Install R Packages

You can chose to install packages with each lesson or you can download all of the necessary R Packages now.

  • raster: install.packages("raster")
  • rgdal: install.packages("rgdal")
  • rasterVis: install.packages("rasterVis")
  • ggplot2: install.packages("ggplot2")

More on Packages in R - Adapted from Software Carpentry.

Download Data

Download NEON Teaching Data Subset: Airborne Remote Sensing Data

The LiDAR and imagery data used to create this raster teaching data subset were collected over the National Ecological Observatory Network’s Harvard Forest and San Joaquin Experimental Range field sites and processed at NEON headquarters. The entire dataset can be accessed by request from the NEON Airborne Data Request Page on the NEON website.

Download NEON Teaching Data Subset: Landsat-derived NDVI raster files

The imagery data used to create this raster teaching data subset were collected over the National Ecological Observatory Network’s Harvard Forest and San Joaquin Experimental Range field sites.
The imagery was created by the U.S. Geological Survey (USGS) using a multispectral scanner on a Landsat Satellite. The data files are Geographic Tagged Image-File Format (GeoTIFF).


Set Working Directory: This lesson assumes that you have set your working directory to the location of the downloaded and unzipped data subsets. An overview of setting the working directory in R can be found here.

R Script & Challenge Code: NEON data lessons often contain challenges that reinforce learned skills. If available, the code for challenge solutions is found in the downloadable R script of the entire lesson, available in the footer of each lesson page.

Working with Spatio-temporal Data in R Series: This tutorial series is part of a larger spatio-temporal tutorial series and Data Carpentry workshop. Included series are introduction to spatio-temporal data and data management, working With raster data in R, working with vector data in R and working with tabular time series in R.

Tutorials in the Series