How to compare the Indian state with areas in the river.

I want to talk about the different states of India with their respective areas in the R software. I tried to use GADM data, level 2 data, to get the coordinates.

I followed this thread Displaying only one state of India and recording its name within the state line . However, I cannot multiply the data for any state and use it for matching.

What I have tried:

map <- fortify(Karnataka)
map$id <- as.integer(map$id) 
dat <- data.frame(id = 216:242, district = Karnataka) 
map_df <- inner_join(map, dat, by = "id") 
centers <- data.frame(gCentroid(Karnataka, byid = TRUE)) 
centers$state <- dat$district

      

+3


source to share


2 answers


I was able to display the state with its district boundaries using the following commands.



India <- getData("GADM", country = "India", level = 2)  
Karnataka <- subset(India, NAME_1 == "Karnataka")
map <- fortify(Karnataka);  
map$id <- as.integer(map$id);  
dat <- data.frame(id = 216:242, district = Karnataka@data$NAME_2);  
map_df <- inner_join(map, dat, by = "id");  
centers <- data.frame(gCentroid(Karnataka, byid = TRUE));  
centers$state <- dat$district;  


ggplot() +
geom_map(data = map_df, map = map_df,
     aes(map_id = id, x = long, y = lat, group = group),
     color = "#ffffff", fill = "#bbbbbb", size = 0.25) +
geom_text(data = centers, aes(label = state, x = x, y = y), size = 2) +
coord_map() + labs(x = "", y = "", title = "Districts of Karnataka") 

      

+1


source


You can do this nicely and easily with Google Maps in R. There ggmap

are many options available. The examples below are very simple but completely customizable, setting the options however you like.

map <- qmap('Karnataka', zoom = 7, maptype = 'hybrid')
map

      

enter image description here



library(ggmap)
qmap('Karnataka')

      

enter image description here

+1


source







All Articles