如何将自定义限制应用于 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)

enter image description here

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

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

enter image description here

map <- tm_shape(World[World$continent == "South America",palette = "Reds")
map

enter image description here

问候,

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...