如何在 R 中的国家地图中为特定区域着色?

How to color specific districts in a country map in R?

我绘制了砂拉越州(在马来西亚国家)的地图以及地区级别的边界,如图所示。

但是我的问题是,如何为特定地区(两个或更多)着色?有人可以帮助我吗,砂拉越的任何地区都可以作为例子。代码如下:

#sarawak map with divisions
library(raster)

#country Malaysia with all boundaries at the district level
Malaysia <- getData('GADM', country='MYS', level=2)
#listing all districts in every states in Malaysia e.g. there are 32 districts for Sarawak state
Malaysia$NAME_1

#plotting Sarawak with all districts and their boundaries
Sarawak <- Malaysia[98:128,]
plot(Sarawak)

首先让我(向所有人)推荐去 CRAN,点击“包”link,然后点击“CRAN 任务视图”link。该页面按一般适用范围收集包;有一整节是关于地图和制图以及 GEOS 等的。

对于您的特殊情况,我认为包 maptools here 中的一些工具是专为给地图中的指定区域着色而设计的。