Skip to content

polygon ID issue with grid_plot_obj  #2

@dill

Description

@dill

From Craig Reddel, the issue:

26/02/2018 20:11, Craig Reddell wrote:

Hello all,

I'm a graduate student at New Mexico State University currently working on developing a Density Surface Model to predict lagomorph densities across my study site. I've been following the example dsm analysis in R with success, except for when I attempt to use ggplot and the grid_plot_obj function. I continue to get the following error:

Error in SpatialPolygonsDataFrame(sp, data) : row.names of data and Polygons IDs do not match

The polygon is a fishnet created in ArcGIS and read into R using the readOGR command and I can plot the grid normally using the plot command. I've checked the data row names and polygon IDs manually using the following code:

all(lapply(pred.polys@polygons, slot, "ID") == row.names(pred.polys@data))

and they appear to be equally numbered (characters starting at "0"). I also reassigned the polygon IDs with the data row names and tried reassigning the preddata rows with the SPDF row names with no success. Navigating forums, I found that this error is a relic of the old readShapeSpatial command and that readOGR reads the shapefile in accounting for this error, otherwise they recommended reassigning the polygon ID values as I had previously done. Just wondering if anyone has encountered this error before or has some thoughts on troubleshooting.

The solution:

Thanks for the response Dave. I ended up altering the grid_plot_obj
function by specifying the spatial data frame to extract the proper row
names with success:

row.names(fill) <- row.names(pred.polys@data)

I'll be sure to continue to make changes that suit my data set. Thanks
again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions