ggmap:从shapefile绘制多边形
使用ggmap,我想在包含一些位置点的地图上包括来自shapefile的市政边界(多边形)。除了绘制多边形外,此脚本会执行所有操作: library(rgdal) library(ggmap) # Get shapefile with Drammen municipality borders tmpzip<-tempfile() tmpdir<-tempfile() dir.create(tmpdir) download.file("http://www.kartverket.no/Documents/Kart/N50-N5000%20Kartdata/33_N5000_shape.zip",tmpzip) unzip(tmpzip, exdir=tmpdir) kommune <- readOGR(dsn=tmpdir, layer="NO_AdminOmrader_pol") kommune<-kommune[kommune$NAVN=="Drammen",] kommune<-spTransform(kommune, CRS("+init=epsg:4326")) # Get location point data subscr<-data.frame(lon=c(10.1237,10.2161,10.2993),lat=c(59.7567,59.7527,59.6863), pop=c(58,12,150)) coordinates(subscr)<-~lon+lat proj4string(subscr)<-CRS("+init=epsg:4326") lon <- c(10.0937,10.3293) lat <- c(59.7916,59.6563) map <- get_map(location = c(lon[1], lat[2], lon[2], lat[1]), maptype = "roadmap", source …