Exercise

Subsetting the neighborhoods

You don't need all those extraneous neighborhoods in New York, so you'll subset out just the neighborhoods in New York County. You already know how!

neighborhoods is a SpatialPolygonsDataFrame and you learned back in Chapter 2 how to subset based on the column in the data slot. The key was creating a logical vector, then subsetting the SpatialPolygonsDataFrame like a data frame.

How can you identify the right neighborhoods? Check out:

head([email protected])

The CountyFIPS is a numeric code that identifies the county. If you can figure out the code for New York County, you can keep just the rows with that value.

Instructions

100 XP
  • The nyc_tracts_merge object also has country codes in the column COUNTYFP. Find the unique() values to find the code for New York County.
  • Subset neighborhoods by adding a logical that tests if neighborhoods$CountyFIPS has the right value.
  • Edit your plot to use manhat_hoods instead of neighborhoods.
  • Add a tm_text() layer, mapping text to "NTAName".