Map of India in R with Different Values of Five Indicators for Every State of India

7.8k views Asked by At

I want to generate a map of India in R. I have five indicators with different values of every state. I want to plot bubbles with five different colors, and their size should represent their intensity in every state. For example:

State A B C D E
Kerala - 39, 5, 34, 29, 11
Bihar - 6, 54, 13, 63, 81
Assam - 55, 498, 89, 15, 48,
Chandigarh - 66, 11, 44, 33, 71

I have gone through some links related to my problem:

[1] http://www.r-bloggers.com/nrega-and-indian-maps-in-r/

[2] An R package for India?

But these links could not serve my purpose. Any help in this direction would be greatly appreciated.

I have also tried

library(mapproj)
map(database= "world", regions  = "India", exact=T, col="grey80", fill=TRUE, projection="gilbert", orientation= c(90,0,90))

lat <- c(23.30, 28.38)

lon <- c(80, 77.12) # Lon and Lat for two cities Bhopal and Delhi

coord <- mapproject(lon, lat, proj="gilbert", orientation=c(90, 0, 90))

points(coord, pch=20, cex=1.2, col="red")

In nut shell problems are: (1) It does not give me plot at district level. Not even boundries of states. (2) How to create bubbles or dots of my data in this plot, if I have only name of locations and corresponding value to plot? (3) can this be done in easily in library(RgoogleMaps) or library(ggplot2)? (Just a guess, I do not know much about these packages)

2

There are 2 answers

0
lawyeR On

Once you have the shapefile for India, you need to create a choropleth. That will take the shapefule map and color each State in India on a gradient that reflects your data. You may want to create a panel of five plots, each one showing India and its states colored according to one of your five variables.

For others who can push this answer farthr, here is the dput of the data frame, after a bit of cleaning.

dput(df)
structure(list(State = c("Kerala", "Bihar", "Assam", "Chandigarh"
), A = c("39", "6", "55", "66"), B = c("5", "54", "498", "11"
), C = c("34", "13", "89", "44"), D = c("29", "63", "15", "33"
), E = c("11", "81", "48", "71")), .Names = c("State", "A", "B", 
"C", "D", "E"), row.names = c("Kerala", "Bihar", "Assam", "Chandigarh"
), class = "data.frame") 
4
Phil On

As @lawyeR states, a choropleth (or thematic) map is more commonly used to represent variables on a map. This would require you to produce one map per variable. Let me take you through an example:

require("rgdal")  # needed to load shapefiles

# obtain India administrative shapefiles and unzip
download.file("http://biogeo.ucdavis.edu/data/diva/adm/IND_adm.zip", 
              destfile = "IND_adm.zip")
unzip("IND_adm.zip", overwrite = TRUE)

# load shapefiles
india <- readOGR(dsn = "shapes/", "IND_adm1")

# check they've loaded correctly with a plot
plot(india)

# all fine. Let's plot an example variable using ggplot2
require("ggplot2")
require("rgeos")  # for fortify() with SpatialPolygonsDataFrame types

india@data$test <- sample(65000:200000000, size = nrow(india@data),
                          replace = TRUE)

# breaks the shapefile down to points for compatibility with ggplot2
indiaF <- fortify(india, region = "ID_1")
indiaF <- merge(indiaF, india, by.x = "id", by.y = "ID_1")

# plots the polygon and fills them with the value of 'test'
ggplot() +
  geom_polygon(data = indiaF, aes(x = long, y = lat, group = group,
                                  fill = test)) +
  coord_equal()

Finally, I notice you asked the same question on GIS SE. This is considered bad practice and is generally frowned upon, so I've flagged that question to be closed as a duplicate of this. As a general rule of thumb try not to create duplicates.

Good luck!