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'.
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)
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With