使用R在GADM地图上绘制城市

Cal*_*tta 4 r r-sp

我试图用GADM数据和使用R绘制印度国家/地区的详细地图.我使用了以下代码

# Load required libraries
library(sp)
library(RColorBrewer)
# ---------------------------------------------------------------------------
# load level 2 india data downloaded from http://gadm.org/country
load("IND_adm2.RData")
ind2 = gadm
# plotting districts of a State, in this case West Bengal
wb2 = (ind2[ind2$NAME_1=="West Bengal",])
spplot(wb2,"NAME_1", main = "West Bengal Districts",
       colorkey=F, scales=list(draw=T))
Run Code Online (Sandbox Code Playgroud)

生成这个地图

地图


我现在正试图插入几个标记(或点加文本)来显示区总部,"Purulia"在lon = 86.36521 lat = 23.33208但不知何故我无法sp.layout正确使用语法.我将需要这个为一组长城拉特知道的城镇.如果有人可以帮我解决这个问题,我将非常感激.

rcs*_*rcs 5

这是一个简短的例子:

library("sp")

# load level 2 india data from gadm.org
library("raster")
ind2 <- getData('GADM', country='IND', level=2)
wb2 <- ind2[ind2$NAME_1=="West Bengal",]

cities <- data.frame(name="Purulia", lon=86.36521, lat=23.33208)

spplot(wb2, "NAME_1",
       sp.layout=list("panel.points", cities$lon, cities$lat, col="red"),
       main="West Bengal Districts",
       colorkey=FALSE, scales=list(draw=TRUE))
Run Code Online (Sandbox Code Playgroud)

或者如果你的城市在SpatialPointsDataFrame:

cities <- data.frame(name="Purulia", lon=86.36521, lat=23.33208)
coordinates(cities) <- ~ lon + lat
class(cities)
# [1] "SpatialPointsDataFrame"

spplot(wb2, "NAME_1",
       sp.layout=list("sp.points", cities, col="red"),
       main="West Bengal Districts",
       colorkey=FALSE, scales=list(draw=TRUE))
Run Code Online (Sandbox Code Playgroud)

ssplot