เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

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.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Visualizing Geospatial Data in R

ดูคอร์ส

คำแนะนำการฝึกหัด

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

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Print pop_by_age


# Subset out the under_1 layer using [[


# Plot the under_1 layer
แก้ไขและรันโค้ด