5

I am doing lots of statistical analysis on county basis in R for US. But I want to do some studies for India as well. I have found state map, but no district map in R. I can find such things in d3.js but I would rather not abandon R.

Is there a R package for India that is similar to 'maps'.

Geekuna Matata
  • 1,349
  • 5
  • 19
  • 38

1 Answers1

8

You can use data from GADM which contains shapefiles on different levels of administrative division so also district level which is level 2 I guess. You can use the script below to directly load the data, code is taken from here.

So in your case you would run:

IND<-getCountries("IND",level=2)

Just to check, plot the data:

plot(ind)

enter image description here

Alternatively you can use GAUL data and load the shapefile using maptools.

Code to get data.

# Load required libraries
library(sp)

# Load file from GADM
# Specify the countries for fileName using ISO3C
# like "AFG" for Afghanistan.
# "level" specifies adminsitrative level.
loadGADM<-function(fileName,level=0,...){
load(url(paste("http://gadm.org/data/rda/",fileName,"_adm",level,".RData",sep = "")))
gadm
}

# Add prefix (ISO3C code) to shapefile.
changeGADMPrefix<-function(GADM, prefix) {
GADM <- spChFIDs(GADM, paste(prefix, row.names(GADM), sep = "_"))
GADM
}

# Load file and change prefix
loadChangePrefix<-function (fileName, level = 0, ...) {
theFile <- loadGADM(fileName, level)
theFile <- changeGADMPrefix(theFile, fileName)
theFile
}

# Apply all the functions:
getCountries <- function (fileNames, level = 0, ...) {
polygon <- sapply(fileNames, loadChangePrefix, level)
polyMap <- do.call("rbind", polygon)
polyMap
}
Community
  • 1
  • 1
horseoftheyear
  • 917
  • 11
  • 23
  • Thank you so much! On a sidenote, how can I add full state of Kashmir in India to this map? If I use this one, I am going to get a lot of flak. Sensitive border issue. – Geekuna Matata Apr 13 '14 at 02:02
  • 2
    That's a good question. So if I compare the plot with an official map it seems that for Jamnu & Kashmir the areas under Chinese and Pakistani line of control are missing. Correct? One way to include them is to also load the ADM2 level data for CHN and PAK and then subset the data to include all Indian districts and the Chinese and Pakistani districts in Kashmir. So those will be Aksai Chin for China, and Azad-Kasmir and Gilgit-Balistan for Pakistan I guess. – horseoftheyear Apr 13 '14 at 11:19
  • Thank you. Could you please change the answer to reflect that change? No hurries on that. Whenever you find time. Basically, this is the official map and no other map is published in India. http://www.nationsonline.org/bilder/map_of_india50.jpg – Geekuna Matata Apr 13 '14 at 18:37
  • I found out that it isn't possible for the Chinese district. See the map in the link (not the best of plots, I know) and compare it with the official map. The Pakistani districts fit well within the defined areas, but the Chinese district also includes territory that really is in China. http://i.imgur.com/netKyma.png – horseoftheyear Apr 13 '14 at 20:18
  • Thanks. This kind of puts me in a spot. – Geekuna Matata Apr 14 '14 at 19:29