Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating maps in R just like the way rworldmap does but for specific country with provinces

I use the rworldmap package with WorldBank Data and I enjoy it. I want to plot maps for Iran, with data related to each province. What are the steps to do that? I know we can plot maps like that in R for some countries like US but not for all countries.

like image 764
Majid Einian Avatar asked Dec 02 '22 15:12

Majid Einian


1 Answers

You can combine rworldmap with the great suggestion from @jazzurro of using raster to get GADM boundaries.

I suspect your main difficulty might be getting the province names to match between your data and the map.

The example below, uses defaults that you can change and just gives a different colour for each province.

library(raster)
library(rworldmap)
## 1 Get map of provinces (level 1 admin regions)
iranLevel1<- raster::getData("GADM", country = "Iran", level = 1)

## 2 join your [data] onto the map by specifying the join column in each
## this will report on any mis-matches between province names
#iranLevel1 <- rworldmap::joinData2Map([data],nameMap="iranLevel1",nameJoinIDMap="NAME_1",nameJoinColumnData=[insert])

## 3 plot map (change NAME_1 to the data you want to plot)
rworldmap::mapPolys(iranLevel1, nameColumnToPlot="NAME_1", addLegend=FALSE)

## 4 add text labels for provinces
text(iranLevel1, label="NAME_1", cex=0.7)

Iran provinces map using rworldmap and raster

Note that joinData2Map(), mapPolys() are more generic equivalents of joinCountryData2Map(), mapCountryData().

Another way of doing this would be to use the choroplethr package.

like image 105
Andy Avatar answered Dec 09 '22 23:12

Andy