参照这里只写了怎么绘制省级、市级地图,这是因为文中找来的地图数据https://datav.aliyun.com/portal/school/atlas/area_selector只到市级。

楼主最近想要绘制县级的地图。在网上一通搜索找到http://xzqh.mca.gov.cn/map这里可以查看县级地图,但是只能查看,不提供下载,略微翻了下网页源代码,看不太懂里面的那些数字,因此没想到怎么把县级地图数据搞下来。请各位路过的坛友们帮忙出出主意吧,感谢大家。

    我发现阿里云的那个地图虽然不能直接下载全国的县级地图数据,但是可以选中一个省以后下载县级地图,理论上我应该是可以把每个省的单独下下来,然后拼接成一个,俺试试。

    可以试试mapchina

    以绘制江西省的县级地图为例:

    install.packages("mapchina")
    
    library(mapchina)
    library(tidyverse)
    library(sf)
    
    province <- china %>%
      filter(Name_Province %in% c("江西省"))
    
    cities <- province %>%
      group_by(Name_Perfecture) %>%
      summarise(geometry = st_union(geometry))
    
    countries <- province %>%
      group_by(Name_County) %>%
      summarise(geometry = st_union(geometry))
    
    ggplot() +
      geom_sf(data = countries,
              aes(fill = factor(generate_map_colors(countries))),
              linetype = "solid", size = 0.5) +
      scale_fill_brewer(palette = "Pastel1") +
      geom_sf(data = province, alpha = 0, linetype = "dashed", size = 0.2) +
      geom_sf(data = cities, alpha = 0, linetype = "solid", size = 1.2) +
      geom_sf_label(data = countries, aes(label = Name_County), size = 2.3) +
      theme_bw() +
      theme(legend.position = "none")

    江西省的县级地图

    一些属性(比如字体大小、坐标轴是否显示)可以根据自己需要再进行调整。

      6 天 后
      9 天 后

      IRONAnthony 跟着你的,我也绘制了湖南地图

      安装并加载必要的包

      install.packages("mapchina") # 如果尚未安装
      install.packages("tidyverse") # 如果尚未安装
      install.packages("sf") # 如果尚未安装

      library(mapchina)
      library(tidyverse)
      library(sf)

      假设 'china' 是一个包含中国各省、市、县的sf对象

      过滤出湖南省的数据

      province <- china %>%
      filter(Name_Province == "湖南省") # 仅选择湖南省

      计算城市和县的几何体

      cities <- province %>%
      group_by(Name_Perfecture) %>%
      summarise(geometry = st_union(geometry))

      countries <- province %>%
      group_by(Name_County) %>%
      summarise(geometry = st_union(geometry))

      绘制湖南省的地图

      ggplot() +
      geom_sf(data = countries,
      aes(fill = factor(generate_map_colors(countries))),
      linetype = "solid", size = 0.5) +
      scale_fill_brewer(palette = "Pastel1") +
      geom_sf(data = province, alpha = 0, linetype = "dashed", size = 0.2) +
      geom_sf(data = cities, alpha = 0, linetype = "solid", size = 1.2) +
      geom_sf_label(data = countries, aes(label = Name_County), size = 2.3) +
      theme_bw() +
      theme(legend.position = "none")