I am interested in having a "good" divergent color pallette. One could obviously use just red, white, and blue:

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

Since I recently fell in love with the viridis color palettes, I was hoping to combine viridis and magma to form such divergent colors (of course, color blind people would only see the absolute value of the color, but that is sometimes o.k.).

When I tried combining viridis and magma, I found that they don't "end" (or "start") at the same place, so I get something like this (I'm using R, but this would probably be the same for python users):

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

enter image description here

We can see that when close to zero, viridis is purple, while magma is black. I would like for both of them to start in (more or less) the same spot, so I tried using 0.3 as a starting point:

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

enter image description here

This is indeed better, but I wonder if there is a better solution.

(I am also "tagging" python users, since viridis is originally from matplotlib, so someone using it may know of such a solution)

Thanks!

推荐答案

I find Kenneth Moreland's proposal quite useful. It has now been implemented as cool_warm in heatmaply:

# 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相关问答推荐

管道末端运行功能

在某些栏和某些条件下,替换dfs列表中的NA

使用tidy—select创建一个新的带有mutate的摘要变量

try 将 colored颜色 编码添加到ggploly的标题中

以相同的方式对每个表进行排序

从R中的对数正态分布生成随机数的正确方法

按时间顺序对不同事件进行分组

如何将使用rhandsontable呈现的表值格式化为百分比,同时保留并显示完整的小数精度?

创建在文本字符串中发现两个不同关键字的实例的数据框

有毒元素与表观遗传年龄的回归模型

长/纬点继续在堪萨斯-SF结束,整齐的人口普查

按组使用dummy r获取高于标准的行的平均值

是否从列中删除★符号?

GOGPLATE geom_boxploy色彩疯狂

将美学添加到ggploy中的文本标签

基于R中的引用将向量值替换为数据框列的值

随机生成样本,同时在R内的随机样本中至少包含一次所有值

从data.table列表中提取特定组值,并在R中作为向量返回

Gggvenn为Venn增加了不存在的价值

移除y轴断开的geom_bar图的外框