我正在尝试使用 ggplot2 对地图进行分面,因为它比 tmap 包更快。遗憾的是我得到的地图并不是我想要的。
library(ggplot2)
library(raster)
library(ggspatial)
chile <- getData("GADM",country="Chile",level=1)
chile2= chile[c(2,4:5,7,8,12:16),]
chile2$grupo=1
chile3= chile[c(1,3,6,9:11),]
chile3$grupo=2
mapa=rbind(chile2, chile3)
ggplot() +
layer_spatial(mapa) +
lims(x = c( -77.1,-65), y = c(-57, -15))+
facet_wrap(~grupo)
Run Code Online (Sandbox Code Playgroud)
遗憾的是上面的地图不是我需要的。通过 tmap,我得到了下面的地图,这正是我真正需要的地图:
你知道如何使用ggplot2解决这个问题吗?