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 code from the Creating spatial data frames by combining regular data frames with spatial objects recipe is repeated to create the SpatialPointsDataFrame object of New Jersey with county-level data.

In step 2, the underlying data frame is accessed through the nj.spdf@data variable and computes the population density based on the population and area_sq_mi variables.

In step 3, the maptools package method, spCbind, is used to add the new variable to the underlying data frame in the SpatialpointsDataFrame object, nj.spdf.

In step 4, the new variable is then plotted.

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