[R-sig-Geo] assigning densities to polygons & chloropleth maps

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sat Dec 14 12:12:48 CET 2013


On Fri, Dec 13, 2013 at 8:06 PM, karengrace84 <kgfisher at alumni.unc.edu> wrote:
> I am looking at fish tagging data throughout the state of Louisiana. I have a
> shapefile of the state divided into 480 polygons, and I would like to make a
> chloropleth map by number of fish tagged in each polygon. Just wondering
> what the best way to do this is.
>
> I have no problem assigning all of the tag locations (gps points) to their
> designated polygon. But I am not sure how to proceed from there.

 So what's the output from that process look like? You want to make a
SpatialPolygonsDataFrame with "NumberOfFish" as one of the variables.
You can work out the number of fish in each polygon from a list of
polygon-ids just by using 'table'. Then match the counts back to the
polygon ids in your SpatialPolygonsDataFrame....

 Once that's done then spplot(df,"NumberOfFish") gets you 99% of the
way there. See the help for spplot for more examples.

> ggplot looks to be the best way to create the graph, but I don't know how to
> get my data in the correct format for that function.

 If you really want to use ggplot/ggmap then you still need a
SpatialPolygonsDataFrame, but you have to "fortify" it and that adds
another level of complication, and I think ggplot still doesn't handle
polygon features with holes and islands as neatly as the routines in
the sp package.

Barry



More information about the R-sig-Geo mailing list