## Raster 04: Work With Multi-Band Rasters - Image Data in R

Last modified: Mar 15, 2016This tutorial explores how to import and plot a multi-band raster in R. It also covers how to plot a three-band color image using the plotRGB function in R.

Source:
National Ecological Observatory Network (NEON)

The tutorials in this series cover how to open, work with and plot raster time
series data in `R`

. This series includes only the more-advanced, time-series
specific tutorials that are also part of the
Introduction to Working With Raster Data in R series.

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 time-series data in `R`

before.

After completing the series you will:

**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.

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).

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.

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.

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.

This tutorial explores how to import and plot a multi-band raster in R. It also covers how to plot a three-band color image using the plotRGB function in R.

This tutorial covers how to work with and plot a raster time series, using an R RasterStack object. It also covers the basics of practical data quality assessment of remote sensing imagery.

This tutorial covers how to efficiently and effectively plot a stack of rasters using rasterVis package in R. Specifically it covers using levelplot and adding meaningful, custom names to band labels in a RasterStack.

This tutorial covers how to extract and plot NDVI pixel values from a raster time series stack in R. We will use ggplot2 to plot our data.