Aan de slagGa gratis aan de slag

A more complicated object

The raster package provides the RasterLayer object, but also a couple of more complicated objects: RasterStack and RasterBrick. These two objects are designed for storing many rasters, all of the same extents and dimension (a.k.a. multi-band, or multi-layer rasters).

You can think of RasterLayer like a matrix, but RasterStack and RasterBrick objects are more like three dimensional arrays. One additional thing you need to know to handle them is how to specify a particular layer.

You can use $ or [[ subsetting on a RasterStack or RasterBrick to grab one layer and return a new RasterLayer object. For example, if x is a RasterStack, x$layer_name or x[["layer_name"]] will return a RasterLayer with only the layer called layer_name in it.

Let's look at a RasterStack object called pop_by_age that covers the same area as pop but now contains layers for population broken into few different age groups.

Deze oefening maakt deel uit van de cursus

Visualizing Geospatial Data in R

Cursus bekijken

Oefeninstructies

  • Print pop_by_age. Can you see the names of all the layers?
  • Subset out the under_1 layer using [[ subsetting.
  • Plot the under_1 layer by passing your code from the previous instruction to plot().

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Print pop_by_age


# Subset out the under_1 layer using [[


# Plot the under_1 layer
Code bewerken en uitvoeren