简体   繁体   中英

How to use a continuous color scale for thematic maps in the R package tmap?

When I make a choropleth with tmap where a continuous variable is mapped to fill color, tmap discretizes the variable and plots color by category. For example, this code

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

produces a map where countries are colored based on whether their GDP per capita is in the range $0-20,000, $20,000-40,000, etc. I would like a map where GDP/capita is mapped continuously to colors or shades of color, so that small differences in GDP entail small differences in color on the map. Does tmap have this capability?

We can use style = cont or order .

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")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM