gpt4 book ai didi

r - 如何用 r 中的地区映射印度州?

转载 作者:行者123 更新时间:2023-12-02 01:36:52 24 4
gpt4 key购买 nike

我想在 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

最佳答案

我可以使用以下命令绘制一个州及其地区边界的 map 。

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com