首页 > 解决方案 > 如何在 R 包 tmap 中为专题图使用连续色标?

问题描述

当我制作一个tmap连续变量映射到填充颜色的等值线时,将变量tmap离散化并按类别绘制颜色。例如,这段代码

library(tmap)
data(World)
tm_shape(World) + tm_polygons(col="gdp_cap_est")

生成一张地图,其中国家根据其人均 GDP 是否在 0-20,000 美元、20,000-40,000 美元等范围内进行着色。我想要一张 GDP/人均连续映射到颜色或颜色阴影的地图,以便小GDP 的差异导致地图上颜色的微小差异。tmap 有这个能力吗?

标签: rgisdata-visualizationchoroplethtmap

解决方案


我们可以使用style=contorder

library(tmap)
data(World)

# Map the value to a continuous gradient
tm_shape(World) + 
  tm_polygons(col = "gdp_cap_est",
              style = "cont")

在此处输入图像描述

# Map the order to a continuous gradient
tm_shape(World) + 
  tm_polygons(col = "gdp_cap_est",
              style = "order")

在此处输入图像描述


推荐阅读