What is a "good" palette for divergent colors in R? (or: can viridis and magma be combined together?)
<p>I am interested in having a "good" divergent color pallette. One could obviously use just red, white, and blue:</p>

<pre><code>img &lt;- 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 &lt;- colorRampPalette(colors = c("red", "white", "blue"))
img(rwb(100), "red-white-blue")
</code></pre>

<p><a href="https://i.stack.imgur.com/eHrwm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eHrwm.png" alt="enter image description here"></a></p>

<p>Since I recently fell in love with the <a href="https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html" rel="noreferrer">viridis color palettes</a>, 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.).</p>

<p>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):</p>

<pre><code>library(viridis)
img(c(rev(viridis(100, begin = 0)), magma(100, begin = 0)), "magma-viridis")
</code></pre>

<p><a href="https://i.stack.imgur.com/255WC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/255WC.png" alt="enter image description here"></a></p>

<p>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:</p>

<pre><code>img(c(rev(viridis(100, begin = 0.3)), magma(100, begin = 0.3)), "-viridis-magma(0.3)")
</code></pre>

<p><a href="https://i.stack.imgur.com/9FJyY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9FJyY.png" alt="enter image description here"></a></p>

<p>This is indeed better, but I wonder if there is a better solution. </p>

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

<p>Thanks!</p>