You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

县级小麦产量分布图州间存在间隙问题求助

解决县级地图间隙问题的方法

核心问题:分组逻辑错误

你当前代码里把group设为state,这会导致同一州内的所有县被当作一个多边形来绘制,自然会出现间隙。正确的做法应该按县级单元分组,比如group = fips或者group = county(取决于你的数据集列名),这样每个县的多边形才能独立正确渲染。

修改后的代码示例

library(maps)
library(urbnmapr)
library(dplyr)
library(ggplot2)

g43 <- wheat_corn_insurance1 %>% 
  filter(year == 1989, wheat == 1) %>%
  ggplot(aes(x = longitude, y = latitude, group = fips, fill = stateproduction/1000)) + 
  geom_polygon(color = NA) + 
  scale_fill_gradient(low = "white", high = "red") + 
  labs(title = "County-Level Choropleth Map", 
       subtitle = "Wheat Production (thousand bu), 1989")

g43

额外排查点

  • 检查你的合并数据集是否包含所有县级FIPS码,有没有遗漏的县,缺失的单元会导致地图出现空白间隙。
  • 确认经纬度数据的精度是否足够,部分低精度的地理坐标也可能导致多边形衔接出现缝隙。
  • 如果用urbnmapr,可以直接用它自带的counties数据集匹配你的产量数据,避免自行合并坐标可能出现的错误:
    # 示例:用urbnmapr自带数据集匹配
    merged_data <- left_join(counties, wheat_corn_insurance1 %>% filter(year == 1989, wheat == 1), 
                             by = c("fips" = "你的FIPS列名"))
    
    ggplot(merged_data, aes(x = long, y = lat, group = group, fill = stateproduction/1000)) +
      geom_polygon(color = NA) +
      scale_fill_gradient(low = "white", high = "red") +
      labs(title = "County-Level Choropleth Map", 
           subtitle = "Wheat Production (thousand bu), 1989")
    

内容的提问来源于stack exchange,提问作者Homa Taheri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 14:34:57