Reputation: 3196
When I run:
maps::map.where('county', y = 40.49069996, x = -94.40780005)
# prints "missouri,webster"
Even through these GPS co-ordinates are for a point in Worth County, Missouri, and not in Webster County:
Upvotes: 2
Views: 77
Reputation: 1037
This is a bug in the maps package. It will be fixed in the forthcoming version 3.2. There is a quick way to avoid the bug, as mweber explains. You can even shorten it to
map.where(map("county",fill=TRUE,plot=FALSE), -94.40780005, 40.49069996)
The bug has probably been around for ages, and only shows for the "counties" database, for missouri countries that follow alphabetically after St Louis.
For the technically minded: In fact, you can manually fix the installed package (or rather: stop the bug from affecting counties data) by editing maps/mapdata/counties.N In that file, you will see that around lines 1545-1564, the line numbers do not correspond to the polygon numbers because someone moved a line. If you move that single line back, everything works again. The actual bug in the R code is that for map databases map.where() assumes the polygon number is equal to the line number in the .N file, which is almost always OK, but fails in this case.
Upvotes: 1
Reputation: 749
I can't say precisely why, but if you subset the counties to Missouri first and add the fill and plot paramters, Worth is returned as result as it should be. I just followed last example in help for map.where in maps package
p <- map('county','Missouri',fill = TRUE, plot = FALSE)
map.where(p, -94.40780005, 40.49069996)
[1] "missouri, worth"
Upvotes: 3