R ggmap中的随机线(bug?)-如何去除它们?

R ggmap中的随机线(bug?)-如何去除它们?,r,google-maps,maps,border,ggmap,R,Google Maps,Maps,Border,Ggmap,我在R(RStudio 0.98)中使用了ggmap(2.4),我有一张缅甸地图,上面有政治边界,我正在绘制一些语言信息。不幸的是,边框与一些随机线一起显示,这些线的颜色与不应显示的颜色相同。一个在北部笔直,另外两个在南部更远的地方延伸到海洋中。我用两个红色箭头标记它们 以下是我的源代码: library(ggmap) burma <- get_map(location=c(lon=96, lat=20), maptype='satellite', color='color', zoom=

我在R(RStudio 0.98)中使用了ggmap(2.4),我有一张缅甸地图,上面有政治边界,我正在绘制一些语言信息。不幸的是,边框与一些随机线一起显示,这些线的颜色与不应显示的颜色相同。一个在北部笔直,另外两个在南部更远的地方延伸到海洋中。我用两个红色箭头标记它们

以下是我的源代码:

library(ggmap)
burma <- get_map(location=c(lon=96, lat=20), maptype='satellite', color='color', zoom=5)
burma.map <- ggmap(burma, darken=c(.33, 'white')) + coord_map(xlim=c(92,102), ylim=c(29,10)) + borders(database="world", colour="yellow")
burma.map
库(ggmap)
缅甸内置的世界地图数据存在问题,将由
地图
软件包的新维护者很快解决(即,即使您有时尝试裁剪多边形,也会遇到问题)。在此期间,使用其他更干净的边框并对其进行裁剪,以便ggplot2不必这样做(因为一旦放入
coord_map
,它自己就无法完成工作):

库(ggmap)
图书馆(sp)
图书馆(rgeos)
图书馆(光栅)
图书馆(地图工具)
图书馆(rgdal)
图书馆(主题)
#获得更好的边界

大家好,安德烈,赫兹利奇·威尔科曼·奥夫·斯塔克沃夫!Danke sehr,少校!我是霍夫,我是里希蒂格^^
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