ComeçarComece de graça

Some useful methods

pop is a RasterLayer object, which contains the population around the Boston and NYC areas. Each grid cell simply contains a count of the number of people that live inside that cell.

You saw in the previous exercise that print() gives a useful summary of the object including the coordinate reference system, the size of the grid (both in number of rows and columns and geographical coordinates), and some basic info on the values stored in the grid. But it was very succinct; what if you want to see some of the values in the object?

The first way is to simply plot() the object. There is a plot() method for raster objects that creates a heatmap of the values.

If you want to extract the values from a raster object you can use the values() function, which pulls out a vector of the values. There are 316,800 values in the pop raster, so you won't want to print them all out, but you can use str() and head() to take a peek.

Este exercício faz parte do curso

Visualizing Geospatial Data in R

Ver curso

Instruções do exercício

  • Call plot() on pop. Can you see where NYC is?
  • Call str() on values(pop).
  • Call head() on values(pop).

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Call plot() on pop


# Call str() on values(pop)


# Call head() on values(pop)
Editar e executar o código