我想用 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
最佳答案
我可以使用以下命令绘制一个州及其地区边界。
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")
关于r - 如何在 r 中绘制带有地区的印度州?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30706542/