如何将印度国家与地区划分为r?

问题描述 投票:3回答:2

我想用R软件中的各个地区绘制印度的不同州。我尝试使用GADM,2级数据来获取坐标。

我跟着这个帖子Mapping just one State of India and writing its name inside the state boundary。但是,我无法对任何状态的数据进行子集化并将其用于映射。

我尝试过的:

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
r maps
2个回答
1
投票

我可以使用以下命令映射状态及其区域边界。

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
投票

您可以使用R中的Google地图轻松完成此操作。在ggmap中有很多选项。下面的示例非常基本,但可以通过设置您喜欢的选项来完全自定义。

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

enter image description here

library(ggmap)
qmap('Karnataka')

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.