I loaded a shapefile in R using readOGR and I named as data.map.

I can see the shape pretty well by using


The issue is that polygons' id (the id of the plot) is not the same with the @data id. What I mean is that, when I run:

plot(data.map[2, ]) 
data.map@data[2, ]

the polygon 2 that is drawed in the plot, is not the one that the data row 2 refers to.

closed as unclear what you're asking by Spacedman, Fran Raga, whyzar, Mapperz May 3 at 13:31

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • provide us your data so that we can check... if the issue is to visualise the data of the object you see (plot), try data.map[2, ]@data. – Bruno Conte Leite May 2 at 15:45
  • The two things in your question (and the third thing in @BrunoConteLeite comment) should all be the same. If not then something weird is going on and we have no chance of explaining it without a reproducible example. My only hunch is maybe what you think is the "id" is not the row number. Does your data have a column named "id"? – Spacedman May 2 at 21:43

I found the solution. The problem was that I performed a merge function in the @data part of my spatialpolygonsdataframe but without adding the all.x = TRUE property. As a result, the rows that did not have corresponding rows were eliminated and the ids were messed.

  • If you've discovered where you went wrong it can be useful to explain that in your answer. Show how the ids (are they attributes?) were "messed up". If that might happen to other people then you are helping. – Spacedman May 3 at 13:11
  • just added the explanation. – Stathis May 4 at 18:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.