Sunday, March 01, 2009

NREGA and Indian maps in R

A few days ago I was reading an article by Jean Drèze and his colleagues on how the first two years of National Rural Employment Guarantee Act (NREGA) has progressed (There was another article by Drèze on NREGA in 2007). The NREGA is empowering the rural people in a radical way:

[ ...] NREGA programmes visualise a decisive break with the past. Ever since independence, rural development has largely been the monopoly of local contractors, who have emerged as major agents of exploitation of the rural poor, especially women. Almost every aspect of these programmes, including the schedule of rates that is used to measure and value work done, has been tailor-made for local contractors. These people invariably tend to be local power brokers. They implement programmes in a top-down manner, run roughshod over basic human rights, pay workers a pittance and use labour-displacing machinery.

NREGA is poised to change all that. It places a ban on contractors and their machines. It mandates payment of statutory minimum wages and provides various legal entitlements to workers. It visualises the involvement of local people in every decision — whether it be the selection of works and work-sites, the implementation of projects or their social audit.

After going through the articles I thought about reproducing the color (gray) coded maps. Of course the best tool to do this would be R. It took a few days to figure out how to do this. The rest of the post (hopefully clearly) will be on how to produce an Indian map gray coded with literacy rate of the state.
  • I assume you have R installed. If not please go to http://cran.r-project.org/ and install R.
  • Next you have to install a CRAN package maptools.
    • Instructions on installing packages is here.
  • If you want a quick introduction to R, I would recommend this terrific tutorial which uses baseball statistics for illustration.
Now on to the exciting part of producing Indian maps:
  • First we need an Indian map. Fortunately there is a free Indian map although it is little old. You can download the Indian map from here.
    • Extract the zip file in an directory and let us call this directory "dir"
  • I got the literacy data [PDF] from the Indian Budget website and put it as a csv file here. Please download it and rename it as literacy.csv and place it in the same directory ("dir") as the maps.
    • Note: I removed a few states (Jharkhand, Chhattisgarh, Uttaranchal) from the original data since the Indian map we have is little dated and does not contain these states. Maybe later on we can figure out how to draw the boundaries for those states.
The code is straightforward. I adapted the code from http://r-spatial.sourceforge.net/gallery/ more specifically fig14.R there.

#---------------------------------------------------------------------------
# packages for manipulating and mapping spatial data
library(maptools)

# set the working directory

# replace dir with your own path
setwd("dir")

# read the shapefile with the digital boundaries

india <- readShapePoly("india_st")

summary(india)
attributes(india)

# read the literacy file

literacy <- read.csv("literacy.csv")

summary(literacy)

rrt <- literacy$X2001

brks <- quantile(rrt, seq(0,1,1/7), na.rm=T)

cols <- grey(2:(length(brks))/length(brks))

dens <- (2:length(brks))*3

plot(india,col=cols[findInterval(rrt, brks, all.inside=TRUE)])

#---------------------------------------------------------------------------

Here is the output if everything goes fine. Darker shades means dire literacy levels.

No comments: