简体   繁体   English

R:在 tmap map 中删除岛

[英]R: Remove island in a tmap map

I am trying of remove islands using tmap.我正在尝试使用 tmap 删除岛屿。

Frequently I use lims to remove islands in ggplot:我经常使用 lims 来删除 ggplot 中的岛屿:

library(tmap)
library(ggplot2)
library(raster)

chile  <- getData("GADM",country="Chile",level=1)

ggplot()+
    geom_polygon(data=chile, aes(x=long, y=lat, group = group),
         color = "#666666") +
         coord_equal() + 
         lims(x = c( -77.2,-60), y = c(-60, -15))

ggplot Chile map ggplot 智利 map

But tmap dont allow use lims and island disturb the map from continent:但是 tmap 不允许使用 lims 和 island 干扰来自大陆的 map:

tm_shape(chile) +
tm_borders()   

tmap Chile with islands tmap 智利与岛屿

I use facet with tmap because it give better results to me but islands its a problem to me:我将 facet 与 tmap 一起使用,因为它给我带来了更好的结果,但岛屿对我来说是个问题:

    chile2= chile[c(2,4:5,7,8,12:16),]
    chile2$group=1
    chile3= chile[c(1,3,6,9:11),]
    chile3$group=2
    map_split=rbind(chile2, chile3)

    tm_shape(map_split) +
    tm_borders() +
    tm_facets(by = "group")

tmap Chile facet tmap 智利方面

You can see how islands dont allow get a good facet map.您可以看到岛屿不允许获得良好的方面 map。

Do you know how remove islands in a tmap map?你知道如何删除 tmap map 中的岛屿吗?

Thanks谢谢

You can remove the areas you do not want from the dataset.您可以从数据集中删除不需要的区域。

library(raster)
chile  <- getData("GADM",country="Chile",level=1)
xchile <- crop(chile, extent(-85,-59, -61, -14))

It takes a while to run as chile is a rather complex dataset because it has so many islands运行需要一段时间,因为智利是一个相当复杂的数据集,因为它有很多岛屿

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM