How keep information from shapefile after fortify()

后端 未结 4 930
萌比男神i
萌比男神i 2021-02-05 10:06

How can I keep polygons\'s information after shapefile? Let me try to explain:

I have a shapefile with this data:

> head(mapa@data)
         ID      C         


        
4条回答
  •  天命终不由人
    2021-02-05 10:30

    I came across the same problem and was able to achieve the desired results using slightly different approach.

    Import and fortify

    I have used the following code to read the shapes:

    shps <- maptools::readShapePoly(fn = file.path("file",
                                                   "path",
                                                   "no extension"),
                                         # Column with unique IDs
                                         IDvar = "geoID")
    

    and subsequently fortified the objet using the code:

    shpsFort <- ggplot2::fortify(model = shps)
    

    Results

    This created a data.frame object with the id value corresponding to the column passed in IDvar = "geoID". Adding any other data could be simply addressed via ordinary merge command.

提交回复
热议问题