什么是“好"?R中不同颜色的调色板?(或者:绿色和岩浆可以结合在一起吗?) [英] What is a "good" palette for divergent colors in R? (or: can viridis and magma be combined together?)

查看:28
本文介绍了什么是“好"?R中不同颜色的调色板?(或者:绿色和岩浆可以结合在一起吗?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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),红白蓝")

因为我最近爱上了

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

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

这确实更好,但不知道有没有更好的解决方案.

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

谢谢!

解决方案

我找到了 与内插的 RColorBrewer RdBu"相比,它的实际效果如下:

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")

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")

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)")

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)")

This it how it looks like in action compared to an interpolated RColorBrewer "RdBu":

这篇关于什么是“好"?R中不同颜色的调色板?(或者:绿色和岩浆可以结合在一起吗?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆