如何将自定义限制应用于 tmap 中的连续色带

How to apply custom limits to continuous color ramp in tmap

假设我想绘制世界地图,其中国家/地区按人口估计值着色,但我希望色带以指定值开始和停止(例如,也许我想对多张地图使用一个图例)。

library(tmap)
data(World)

# custom color ramp
colorRamp <- colorRampPalette(c('blue', 'yellow', 'red'))

# I can plot the full range of values with my custom palette
tm_shape(World) + tm_fill('pop_est', palette = colorRamp(100))

现在假设我要指定自定义下限和上限:

customRange <- c(200, 700)

breaks <- seq(from = customRange[1], to = customRange[2], length.out = 100)

tm_shape(World) + tm_fill('pop_est', palette = colorRamp(100), breaks = breaks)

这个明显不行,传说也有问题。我收到以下警告:

Warning messages:
1: Values have found that are less than the lowest break 
2: Values have found that are higher than the highest break 

关于正确执行此操作的任何建议?谢谢!

编辑:

进一步说明:在这个例子中,我绘制的数据范围从 1.4 亿到 14 亿。但是假设我有第二张地图,范围从 5 亿到 50 亿。如果我希望两张地图具有相同的配色方案,并且两者都有一个图例,那么我希望两张地图的调色板跨越 1.4 亿到 50 亿。

那么,如何指定调色板跨越的最小值和最大值?

在此处找到解决方案:How to adjust color palette with customized breaks in tmap?

人口以百万计,你也应该定义更少的休息时间。

map <- tm_shape(World[World$continent == "North America",]) + 
  tm_fill('pop_est', 
          breaks = c(0, 100000000, 200000000, 300000000, 400000000),
          style = "fixed",
          palette = "Reds")
map

map <- tm_shape(World[World$continent == "South America",]) + 
  tm_fill('pop_est', 
          breaks = c(0, 100000000, 200000000, 300000000, 400000000),
          style = "fixed",
          palette = "Reds")
map

此致,