简体   繁体   中英

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

I have plot the map for Sarawak state(in the country Malaysia) along with the boundaries at district level as shown in diagram. 在此处输入图像描述

However my question is, how can I color specific districts(two or more)? Can someone help me, any districts in Sarawak will do as an example. Code are as below:

#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)

Let me start by recommending (to everyone) to go to CRAN , clicking on the "packages" link, and then on the "CRAN Task Views" link. That page collects packages by general area of applicability; there's a whole section on maps and mapping and GEOS, etc.

For your particular case, I think some of the tools in the package maptools here are designed for coloring designated regions in a map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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