如何解决如何将自定义限制应用于 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",palette = "Reds")
map
问候,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。