“内置”世界地图数据存在问题,maps 软件包的新维护者将很快解决这些问题(即,即使有时尝试裁剪多边形也会遇到问题)。在此期间,使用其他更干净的边框并裁剪它们,这样 ggplot2 就不必这样做了(因为一旦将coord_map 扔进去,它自己就不会做好):
library(ggmap)
library(sp)
library(rgeos)
library(raster)
library(maptools)
library(rgdal)
library(ggthemes)
# get better borders
url <- "http://thematicmapping.org/downloads/TM_WORLD_BORDERS_SIMPL-0.3.zip"
fil <- "tm.zip"
if (!file.exists(fil)) download.file(url, fil)
unzip(fil, exdir="tm")
world_borders <- readOGR("./tm/TM_WORLD_BORDERS_SIMPL-0.3.shp", "TM_WORLD_BORDERS_SIMPL-0.3")
# get the google map first so we know the bounding box
burma <- get_map(location=c(lon=96, lat=20), maptype='satellite', color='color', zoom=5)
# get the bounding box
bb <- as.numeric(attr(burma, "bb"))
# clip the borders to the bounding box
clip_region <- as(extent(bb[2], bb[4], bb[1], bb[3]), "SpatialPolygons")
proj4string(clip_region) <- proj4string(world_borders)
clipped_borders <- fortify(crop(world_borders, clip_region))
# plot the map
burma_map <- ggmap(burma, darken=c(.33, 'white'))
burma_map <- burma_map + geom_map(data=clipped_borders, map=clipped_borders,
aes(x=long, y=lat, map_id=id),
color="yellow", alpha=0)
burma_map <- burma_map + coord_map(xlim=c(92,102), ylim=c(29,10))
burma_map <- burma_map + theme_map()
burma_map
# alternatively use just asia read directly from GeoJSON URL
# NOTE this relies on some of the above code
# GeoJSON Asia extract made with http://geojson-maps.kyd.com.au/
# But you could use any NaturalEarth extract. This is less
# granular than the previous one
just_asia <- readOGR("https://gist.githubusercontent.com/hrbrmstr/94bdd47705d05a50f9cf/raw/0ccc6b926e1aa64448e239ac024f04e518d63954/asia.geojson",
"OGRGeoJSON")
clipped_borders_ja <- crop(just_asia, clip_region)
clipped_borders_ja <- fortify(clipped_borders_ja)
burma_map <- ggmap(burma, darken=c(.33, 'white'))
burma_map <- burma_map + geom_map(data=clipped_borders_ja, map=clipped_borders_ja,
aes(x=long, y=lat, map_id=id),
color="yellow", alpha=0)
burma_map <- burma_map + coord_map(xlim=c(92,102), ylim=c(29,10))
burma_map <- burma_map + theme_map()
burma_map
墨卡托是目前使用coord_map 所能获得的最好的。专题制图站点的“锐利”边界也较少。越精确,使用它们所需的时间就越长。