Plotting Cities on a GADM map with R

心已入冬 提交于 2019-12-05 12:37:09

Here is how you can do that with base plot (instead of 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)

Here is a short example:

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

or if you have your cities in a 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))

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!