在 RStudio 中为分区统计图创建中断和设置颜色时出现问题

Problem with creating breaks and setting colours for choropleth maps in RStudio

提问人:Ben Jones 提问时间:9/25/2023 最后编辑:Ben Jones 更新时间:9/26/2023 访问量:36

问:

我正在尝试绘制埃塞俄比亚的分区统计图,该地图显示了每个区域(县)的国内流离失所者 (IDP) 人数占总人口的百分比。我已将埃塞俄比亚 Shapefile 上传到 R (Ethiopia_geoboundaries_ADM2),以及埃塞俄比亚 (Ethiopia_Rmap) 的 %IDP 数据并将它们合并。但是,当我使用 spplot 时,颜色范围仅适合当前数据范围。我想将这些结果与其他国家/地区进行比较,因此希望为每张地图提供一组统一的分色间隔。

我想要的颜色细分是:<5%、5-10%、10-25%、25-50%、50-75%、75%+

当前代码和输出:

> setwd("~/Documents/Acumen_Data/IDMC_Map_Data/Ethiopia")
> library(spdep)
> library(rgdal)
> library(sf)
> library(terra)
> Ethiopia_Rmap <- read_excel("Ethiopia_Rmap.xlsx")
> Ethiopia_geoBoundaries_ADM2 <- readOGR(dsn = ".", layer = "eth_admbnda_adm2_csa_bofedb_2021")
> Ethiopia_Static_Map = merge(Ethiopia_geoBoundaries_ADM2,Ethiopia_Rmap,by.x="ADM2_EN",by.y="Zone")
> ColourPalette = brewer.pal(n=7, name="PuBu")
> spplot(Ethiopia_Static_Map,"IDP_Perc", col.regions=ColourPalette)

这是当前的输出映射

这是Ethiopia_Rmap人口百分比数据

这是埃塞俄比亚 shapefile

我想要一张地图,图例有点像这样,而不是从 0-50。我认为这意味着以某种方式定义班级间隔的设置休息时间?请帮忙!谢谢!

示例图例 - 不一定是这些确切的颜色!

Ethiopia_geoboundaries_ADM2数据来自此链接 - https://data.humdata.org/dataset/cb58fa1f-687d-4cac-81a7-655ab1efb2d0/resource/63c4a9af-53a7-455b-a4d2-adcc22b48d28/download/eth_adm_csa_bofedb_2021_shp.zip

使用 dput Ethiopia_Rmap数据示例

Ethiopia_Rmap_Structure = dput(Ethiopia_Rmap[1:30,])

Ethiopia_Rmap = 结构( 列表( 区域 = c( “远方”, “远方”, “远方”, “远方”, “远方”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “阿姆哈拉”, “Benishangul-Gumuz地区”, “Benishangul-Gumuz地区”, “甘贝拉”, “甘贝拉”, “哈拉利”, “奥罗米亚”, “奥罗米亚”, “奥罗米亚”, “奥罗米亚”, “奥罗米亚”, “奥罗米亚”, “奥罗米亚”, “奥罗米亚”, “奥罗米亚” ), 区域 = c( “阿斯威/区域 1”, “Fanti /Zone 4”, “加比/3区”, “哈里/5区”, “基尔巴蒂/2区”, “阿尔戈巴(特别沃雷达)”, “阿维”, “东戈贾姆”, “北贡达尔”, “北谢瓦(上午)”, “北威洛”, “奥罗米亚”, “南贡达尔”, “南威洛”, “瓦格·哈姆拉”, “西戈贾姆”, “阿索萨”, “梅特克尔”, “阿格内瓦克”, “Nuwer”, “哈拉利”, “阿尔西”, “草捆”, “博雷纳”, “东哈拉尔格”, “东韦勒加”, “古吉”, “霍罗·古德鲁·瓦莱加”, “吉玛”, “凯勒姆·瓦莱加” ), IDP_Population = c( 22668, 1531, 28011, 2580, 41786, 4498, 28622, 20633, 25407, 66296, 30243, 7370, 28704, 24292, 38934, 143028, 28603, 94798, 5296, 39208, 3037, 4064, 10650, 220540, 143853, 140374, 100972, 42496, 14893, 26351 ), Total_Population = c( 641584, 333296, 328636, 254909, 489698, 42250, 1328104, 2845753, 4066517, 2464232, 1989563, 611456, 2701503, 3387395, 548884, 2755600, 492344, 441297, 204358, 172105, 283000, 3980967, 2119829, 1431922, 4035797, 1847649, 2073775, 859339, 3638103, 1191582 ), IDP_Perc = c( 3.53, 0.46, 8,22K表 1.01, 8.53, 10.65, 2.16, 0.73, 0.62, 2.69, 1.42米 1.21, 1.16米 0.72, 7.09, 5.19, 5.81, 21.48, 2.59, 22.78, 1.17米 0.1, 0.5, 15.4, 3.56, 7.6, 4.87, 4.95, 0.41, 2.21 ) ), 行名称 = c(NA,-30L), 类 = c(“tbl_df”, “tbl”, “data.frame”) )

r ggplot2 等值统计 rgdal

评论

0赞 Ben Jones 9/26/2023
道歉。错字!
1赞 Axeman 9/26/2023
如果不使代码可重现,您就不太可能收到有用的答案,因此人们可以尝试解决方案。与其分享我们不能使用的数据图片,不如分享一些示例数据,例如 这说明了您的问题。dput
0赞 Ben Jones 9/26/2023
谢谢@Axeman,对这一切非常陌生!

答: 暂无答案