What is a “good” palette for divergent colors in R? (or: can viridis and magma be combined together?)

后端 未结 4 1612
既然无缘
既然无缘 2020-12-07 14:11

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:le         


        
4条回答
  •  忘掉有多难
    2020-12-07 14:34

    I find Kenneth Moreland's proposal quite useful. It is implemented in the Rgnuplot package (install.packages("Rgnuplot") is enough, you don't need to install GNU plot). To use it like the usual color maps, you need to convert it like this:

    cool_warm <- function(n) {
      colormap <- Rgnuplot:::GpdivergingColormap(seq(0,1,length.out=n),
                                                 rgb1 = colorspace::sRGB( 0.230, 0.299, 0.754),
                                                 rgb2 = colorspace::sRGB( 0.706, 0.016, 0.150),
                                                 outColorspace = "sRGB")
      colormap[colormap>1] <- 1 # sometimes values are slightly larger than 1
      colormap <- grDevices::rgb(colormap[,1], colormap[,2], colormap[,3])
      colormap
    }
    
    img(red_blue_diverging_colormap(500), "Cool-warm, (Moreland 2009)")
    

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

提交回复
热议问题