Search code examples
rmappingspatial

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. enter image description here

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)

Solution

  • 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.