用R在GADM地图上绘制城市

用R在GADM地图上绘制城市,r,sp,R,Sp,我试图用GADM数据和R绘制印度各州/地区的详细地图。我使用了以下代码 # Load required libraries library(sp) library(RColorBrewer) # --------------------------------------------------------------------------- # load level 2 india data downloaded from http://gadm.org/country load("IND_

我试图用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))
要生成此地图



我现在正试图加入几个标记(或点加文本)来显示地区总部,lon=86.36521 lat=23.33208的“Purulia”,但不知何故,我无法正确使用
sp.layout
语法。我将需要这一套城镇的长期,拉特将是众所周知的。如果有人能帮我解决这个问题,我将非常感激。

这里有一个简短的例子:

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))

以下是如何使用基本绘图(而不是spplot/LEVELCLOT)实现此功能

库(光栅)
#获取数据

ind2不清楚为什么使用spplot而不是plot。请提供一个可复制的示例,例如,使用允许您下载gadm数据的命令和创建Purulia的命令。此解决方案运行良好。现在我需要看看如何将城市名称放在标记旁边,但这可能会使地图变得非常笨拙。非常感谢提供的解决方案
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))
library(raster)
# get the data 
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)

# plot
plot(wb2, border='gray', col='light gray')
points(cities[, 2:3], col='red', pch=20)
text(cities[, 2:3], labels= cities[,1], pos=4)