code not working for other shp files

前端 未结 1 967
甜味超标
甜味超标 2021-01-22 02:56

The question posed in here , has been solved but somehow it is not working for a different shp file. Any idea why? I have been trying with the shp file from Coloring the states

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-22 03:37

    Your merge is matching each row more than once, creating duplicate rows in the data. Additionally there is an ordering problem, and you lose polygons when there isn't a matching row.

    Replace

    f_india <- merge(x=f_india, y=india@data, by.x="id", by.y="ID")
    

    with

    f_india <- merge(x=f_india, y=unique(india@data), by.x="id", by.y="ID",all.x=T)
    f_india <- f_india[with(f_india, order(id, order)), ]
    

    EDIT:

    Here's the output I get. The grey polygons are caused by mismatched names, but this is the only issue I can see.

    working map

    0 讨论(0)
提交回复
热议问题