Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:删除tmap地图中的孤岛_R_Facet_Tmap - Fatal编程技术网

R:删除tmap地图中的孤岛

R:删除tmap地图中的孤岛,r,facet,tmap,R,Facet,Tmap,我正在尝试使用tmap删除孤岛 我经常使用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

我正在尝试使用tmap删除孤岛

我经常使用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))

我在tmap中使用facet,因为它给我带来了更好的结果,但这对我来说是个问题:

    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地图中的岛屿吗


谢谢

您可以从数据集中删除不需要的区域

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