我有兴趣拥有一个"好"的发散色托盘.很明显,可以只使用红色、白色和蓝色:

img <- function(obj, nam) {
  image(1:length(obj), 1, as.matrix(1:length(obj)), col=obj, 
        main = nam, ylab = "", xaxt = "n", yaxt = "n",  bty = "n")
}
rwb <- colorRampPalette(colors = c("red", "white", "blue"))
img(rwb(100), "red-white-blue")

enter image description here

因为我最近爱上了viridis color palettes,所以我希望将翡翠和岩浆结合起来,形成这种不同的 colored颜色 (当然,色盲的人只会看到 colored颜色 的绝对值,但有时也可以).

当我try 组合viridis和magma时,我发现它们不会在同一个位置"结束"(或"开始"),所以我得到了类似的结果(我使用的是R,但对于python用户来说可能是一样的):

library(viridis)
img(c(rev(viridis(100, begin = 0)), magma(100, begin = 0)), "magma-viridis")

enter image description here

我们可以看到,当接近零时,翡翠是紫色的,而岩浆是黑色的.我希望它们都从同一个点开始(或多或少),所以我try 使用0.3作为起点:

img(c(rev(viridis(100, begin = 0.3)), magma(100, begin = 0.3)), "-viridis-magma(0.3)")

enter image description here

这确实更好,但我想知道是否有更好的解决方案.

(我也在"标记"python用户,因为viridis最初来自matplotlib,所以使用它的人可能知道这样的解决方案.)

谢谢

推荐答案

我觉得Kenneth Moreland's proposal英镑很有用.它现在已在heatmaply年实施为cool_warm:

# install.packages("heatmaply")
img(heatmaply::cool_warm(500), "Cool-warm, (Moreland 2009)")

cool-warm colormap This it how it looks like in action compared to an interpolated RColorBrewer "RdBu": comparison

R相关问答推荐

使用 lapply 函数修改 R 中的几个矩阵

使用 parse - expr()、quo - name() 和 enquo() 定义用于在 ggplot 中绘制国家/地区图表的字符对象

在数据框中有条件地将增长率应用于给定的初始值

为 ID 的不同值随时间创建增量变量

用 dplyr 和条件进行总结

使用替代语法方法在 R 中定义函数

在 R 中创建一个发布就绪表,将组作为嵌套列

R 条形图中日期的 X 轴向左移动

使字符串中的所有实例都包含 5 个或更少的字符

R:过滤包含列表的数据框

计算值出现在 R 中任意两列中的行数

Rowsum 具有特定名称模式的几组列

如何更改类别在堆叠图中的显示顺序并删除 r 中图例中的a?

有没有办法在 R 中的绘图之间切换?

如何在 R 中按年划分日历热图?

删除 - 之后的所有数据在数据栏

使用accumulate将列表中的数据帧反连接到原始的先前数据帧

Ggplot2 - 绘制 2 x geom - hlines() 其中 x 轴是分类因子

按组统计行数,得到不同列的比例

在 r 中try 创建甘特图