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

时间:2015-05-04 02:21:50

标签: 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))

生成此地图

map

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

2 个答案:

答案 0 :(得分: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))

或者如果您的城市位于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))

ssplot

答案 1 :(得分:2)

以下是基本图(而不是spplot / levelplot)

的方法
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)