geom_scatterpie绘制带饼图的地图异常问题求助
排查geom_scatterpie绘制太平洋中心地图异常问题
环境信息
- R版本:4.1.1
- scatterpie版本:0.2.1
- ggplot2版本:3.4.2
问题说明
尝试绘制以太平洋为中心、叠加饼图的世界地图,但生成的map_try_1和map_try_2图像显示异常,现附上运行脚本及输入文件内容,请求排查问题原因。
运行脚本
library(ggplot2) library(scatterpie) ############################################################################## lat_lon_province <- read.csv("lat_lon_province.txt", sep =" ") pies <- read.csv("pies.txt", sep =" ") colnames(pies)[colnames(pies) == "Province"] ="PROVINCE" pies_ecoregion_lat_lon <- merge(pies, lat_lon_province, by = "PROVINCE") pies_ecoregion_lat_lon[is.na(pies_ecoregion_lat_lon)] <- 0 colnms=c("Copepoda", "Isopoda", "Nematoda", "Cestoda", "Trematoda", "Monogenea", "Myxozoa") pies_ecoregion_lat_lon$Total_parasites<-rowSums(pies_ecoregion_lat_lon[,colnms]) n <- nrow(pies_ecoregion_lat_lon) pies_ecoregion_lat_lon$radius <- 6 * abs(rnorm(n)) lon_min <- 80 lon_max <- 270 lat_min <- -50 lat_max <- 50 # 使用map_data() pacific_world <- map_data("world2") # world2MapEnv或world2 # 这是世界数据库的替代版本,基于纬度范围[0, 360),将太平洋置于地图中心。 mapplot_pacific <- ggplot(pacific_world) + geom_map(data = pacific_world, map = pacific_world, aes(x=long, y=lat, map_id=region), col = "white", fill = "gray50") + theme_bw() mapplot_pacific + coord_map(xlim=c(lon_min, lon_max), ylim=c(lat_min, lat_max)) + geom_scatterpie(aes(x=Longitude, y=Latitude, r=radius), data = pies_ecoregion_lat_lon, cols = colnames(pies_ecoregion_lat_lon[,c(3:9)]), color=NA, alpha=.8) + geom_scatterpie_legend(pies_ecoregion_lat_lon$radius, x=240, y=35) ggsave("map_try_1.png", width = 10) ############################################################################### pacific_map <- fortify(pacific_world, xlim = c(lon_min, lon_max), ylim = c(lat_min, lat_max), fill = T, plot = F) pacific <- ggplot(pacific_map) ggplot(pacific_map, aes(x = long, y = lat, group = group)) + geom_polygon() + coord_map(xlim=c(lon_min, lon_max), ylim=c(lat_min, lat_max)) + geom_scatterpie(aes(x=Longitude, y=Latitude, group = PROVINCE, r=radius), data = pies_ecoregion_lat_lon, cols = colnames(pies_ecoregion_lat_lon[,c(3:9)]), color=NA, alpha=.8) + geom_scatterpie_legend(pies_ecoregion_lat_lon$radius, x=240, y=35) + theme_bw() ggsave("map_try_2.png", width = 10)
输入文件内容
pies.txt
| 区域名称 | 鱼类数量 | 桡足类 | 等足类 | 线虫类 | 绦虫类 | 单殖吸虫类 | 吸虫类 | 粘孢子虫类 |
|---|---|---|---|---|---|---|---|---|
| 东珊瑚三角区 | 3 | 24 | 6 | 4 | 2 | |||
| 爪哇过渡区 | 14 | 1 | ||||||
| 豪勋爵岛与诺福克群岛 | 2 | 3 | 2 | 1 | ||||
| 澳大利亚东北大陆架 | 82 | 89 | 28 | 21 | 55 | 109 | 238 | 19 |
| 澳大利亚西北大陆架 | 51 | 14 | 7 | 3 | 2 | 26 | 2 | |
| Sahul大陆架 | 22 | 46 | 26 | 4 | 28 | 12 | 9 | |
| 南海 | 563 | 24 | 62 | 2 | 2 | |||
| 南黑潮区 | 21 | 24 | ||||||
| 巽他大陆架 | 311 | 29 | 11 | 3 | 1 | |||
| 热带西北太平洋区 | 2 | 31 | 14 | 9 | ||||
| 热带西南太平洋区 | 14 | 913 | 154 | 48 | 82 | 220 | 393 | 27 |
| 西珊瑚三角区 | 26 | 605 | 122 | |||||
| 中波利尼西亚区 | 1 | 42 | 10 | 6 | 2 | |||
| 复活节岛 | 1 | 1 | ||||||
| 夏威夷 | 27 | 254 | 225 | 32 | 16 | 66 | 668 | 8 |
| 马克萨斯群岛 | 213 | 4 | 1 | |||||
| 马绍尔、吉尔伯特与埃利斯群岛 | 407 | 96 | 10 | 37 | 16 | 105 | 13 | |
| 东南波利尼西亚区 | 1041 | 8 | 36 | 1 | 18 | 21 |
lat_lon_province.txt
| 区域名称 | 纬度 | 经度 |
|---|---|---|
| 东珊瑚三角区 | -9.989942453 | 153.1554975 |
| 爪哇过渡区 | -9.398129883 | 103.2355709 |
| 豪勋爵岛与诺福克群岛 | -30.3708992 | 163.7689972 |
| 澳大利亚东北大陆架 | -14.61130754 | 147.613617 |
| 澳大利亚西北大陆架 | -17.00240261 | 117.3920957 |
| Sahul大陆架 | -9.727364469 | 129.9578054 |
| 南海 | 15.50365482 | 113.5205013 |
| 南黑潮区 | 23.64450073 | 127.5490036 |
| 巽他大陆架 | 4.935839414 | 107.017955 |
| 热带西北太平洋区 | 8.891712166 | 148.0158917 |
| 热带西南太平洋区 | -20.82816019 | 177.8582737 |
| 西珊瑚三角区 | -4.840562086 | 127.5081903 |
| 中波利尼西亚区 | -9.675919844 | -164.9687772 |
| 复活节岛 | -26.84119987 | -107.4769974 |
| 夏威夷 | 22.68499947 | -163.0189972 |
| 马克萨斯群岛 | -9.251319885 | -139.6159973 |
| 马绍尔、吉尔伯特与埃利斯群岛 | 4.272244259 | 171.2996466 |
| 东南波利尼西亚区 | -20.34943869 | -159.067165 |
内容的提问来源于stack exchange,提问作者Christina P
相关产品推荐
相关产品推荐

