O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required