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

R语言ggplot空间地图优化:三类可视化调整需求咨询

地图可视化调整需求

我通过sf包导入了包含某国1874个地区信息的GeoDataFrame(命名为gdf),其数据结构如下:

Classes ‘sf’ and 'data.frame':  1874 obs. of  8 variables:
$ NOMBDIST: chr  "CODO DEL POZUZO" "TOURNAVISTA" "ALEXANDER VON HUMBOLDT" "IRAZOLA" ...
$ POBTOTAL: num  7768 6219 6085 10941 9003 ...
$ UBIGEO  : num  100902 100904 250305 250302 250304 ...
$ MC_PR   : num  41 41.4 46 43.8 35.3 ...
$ C_PR    : num  9.23 5.22 3.27 2.64 2.21 ...
$ TT      : num  1084 556 1530 2769 1535 ...
$ IDH     : num  0.324 0.409 0.423 0.378 0.437 ...
$ geom    :sfc_MULTIPOLYGON of length 1874; first list element: List of 1
..$ :List of 1
.. ..$ : num [1:1294, 1:2] -75.3 -75.3 -75.3 -75.3 -75.3 ...
..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
- attr(*, "sf_column")= chr "geom"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA
..- attr(*, "names")= chr [1:7] "NOMBDIST" "POBTOTAL" "UBIGEO" "MC_PR" ...

各字段含义:

  • NOMBDIST:地区名称
  • POBTOTAL:地区总人口
  • UBIGEO:地区编码
  • MC_PR:从事科研岗位女性占比(取值范围0-100)
  • C_PR:从事科研岗位人员占比
  • TT:总就业人数(取值范围0-496913)
  • IDH:人类发展指数

获取地区质心(centroids)后,我用以下代码生成地图:

ggplot() +
  geom_sf(data = gdf, fill = "white",size=0.3) +
  geom_sf(
    data = centroids,
    pch = 21,
    aes(size = TT, fill = MC_PR),
    col = "grey20",
    alpha = 0.8) +
  scale_size(
    range = c(1, 9)) +
    scale_fill_gradientn(
    colours = hcl.colors(5, "RdBu", rev = TRUE,alpha = 0.5)) +
  guides(fill = guide_legend(title = "")) +
  theme_void() +
  theme(legend.position = "left")

我需要对地图做以下三项调整,目前尚未实现:

  1. 移除圆圈的边框线(或大幅调细边框)——之前在pch=21后添加size=0.1仅改变了圆圈大小,未影响边框
  2. MC_PR的取值范围是0-100,但图例显示为-3到3,希望将图例改为**Natural Jenks(自然断点)**分类
  3. TT的取值范围是0-496913,但图例显示为0、5、10、15、20,希望将图例改成指定区间分类:0-1000;1001-30000;30001-100000;100001-200000;200001及以上

内容的提问来源于stack exchange,提问作者José Carlos Rojas

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 20:34:57