In step 1, the maps, maptools, and sp packages are loaded.
In step 2, the map function in the maps package is used to get the county map of New Jersey.
From the maps package, we can get maps as lines or polygons. To color regions (such as countries on a world map or states or counties on country maps) based on their data values, we need to have the regions represented as polygons. The fill parameter controls whether or not we get a map as lines or polygons. We used the fill = TRUE option to get the map as polygons.
We will first convert the map to a SpatialPolygons object and then add nonspatial attribute values to make it a SpatialPolygonsDataFrame object.
Every polygon in a SpatialPolygons object must have a unique ID. From ...