Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems black-to-red or red-to-darkred gives you very little color space to work with. You can use hex code to assign more specific colors to your low and high settings, and add a black background to improve contrast. For instance:</p> <pre><code>+ scale_colour_gradient2(low="#22FF00", mid="white", high="#FF0000", midpoint=median(iris$Sepal.Length)) + theme(panel.grid=element_blank(), panel.background=element_rect(fill="black")) </code></pre> <p>gives you much more contrast. Note that I am using <code>scale_color_gradient2</code>, which allows you to set a midpoint color and ascribe it to a summary statistic of the data (here, I used the median). I also used two colors at relatively opposite ends of the spectrum. Adding the above to your code produces:</p> <p><img src="https://i.stack.imgur.com/OVTI4.jpg" alt="high-contrast scatterplot"></p> <p>But aside from playing around with the specific colors until you're satisfied (<a href="http://www.rapidtables.com/web/color/RGB_Color.htm" rel="noreferrer">http://www.rapidtables.com/web/color/RGB_Color.htm</a> and <a href="http://tools.medialab.sciences-po.fr/iwanthue/" rel="noreferrer">iwanthue</a> are good resources for picking colors), I don't know if there exists a way to set a gradient so that contrast is maximized <em>throughout</em>, without creating some ungodly complex rainbow of colors. As you probably know, contrast between any two given points in your data is directly proportional to the difference between the values of those points, so varying that relationship within different locales of your gradient probably isn't desirable, and to my knowledge is not possible in ggplot2.</p> <p>EDIT: Another way to improve contrast is to color by the rank-order of your desired variable (in this example, Sepal.Length) instead of the variable itself. This creates a uniform distribution, which will "spread out" your data by giving equal distance between quantiles. HOWEVER, this may produce a misleading visualization of your data--if your data are highly skewed, some identical/near-identical values could be represented by fairly contrasting colors. So use with caution.</p> <p>Compare with above:</p> <pre><code>iris &lt;- iris[with(iris, order(Sepal.Length)),] iris$rank &lt;- 1:150 ggplot(iris) + geom_point(aes(x=Sepal.Width, y=Sepal.Length, colour=rank)) + scale_colour_gradient2(low="#22FF00", mid="white", high="#FF0000", midpoint=median(iris$rank)) + theme(panel.grid=element_blank(), panel.background=element_rect(fill="black")) </code></pre> <p><img src="https://i.stack.imgur.com/l59t2.jpg" alt="high-contrast scatterplot with color by rank-ordered data"></p> <p>Also, I realize that red-to-green is the least-colorblind-safe choice of colors possible. So you will want to choose colors so that your spectrum doesn't include red or green.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload