I am trying of remove islands using tmap.
Frequently I use lims to remove islands in 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))
But tmap dont allow use lims and island disturb the map from continent:
tm_shape(chile) +
tm_borders()
I use facet with tmap because it give better results to me but islands its a problem to me:
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")
You can see how islands dont allow get a good facet map.
Do you know how remove islands in a 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