Color bar legends for neuroimaging in R

Sometimes the color bar legends that come out of neuroimaging tools don't look that nice. Here is a function to make custom color bars in R, which can then be saved as pdf and used wherever you like:

Examples

Basic p-value color bar. Only 5 tick marks used, and title added.

lut = rev(rainbow(100, start=rgb2hsv(col2rgb('red'))[1], end=rgb2hsv(col2rgb('yellow'))[1]))
color.bar(lut, 0, 0.05, title='p-values', nticks=5)

Two-sided p-value color bar (shows the direction of the effect). Default 11 ticks.

cool = rainbow(50, start=rgb2hsv(col2rgb('cyan'))[1], end=rgb2hsv(col2rgb('blue'))[1])
warm = rainbow(50, start=rgb2hsv(col2rgb('red'))[1], end=rgb2hsv(col2rgb('yellow'))[1])
lut  = c(rev(cool), rev(warm))
color.bar(lut, -0.05, 0.05)

Lopsided to emphasize one effect direction or the other. Tick marks specified directly.

cool = rainbow(50, start=rgb2hsv(col2rgb('cyan'))[1], end=rgb2hsv(col2rgb('blue'))[1])
warm = rainbow(25, start=rgb2hsv(col2rgb('red'))[1], end=rgb2hsv(col2rgb('yellow'))[1])
lut  = c(rev(cool), rev(warm))
color.bar(lut, -0.05, 0.025, ticks=c(-0.05, -0.025, 0, 0.025))

Rainbow colorbar for showing effect sizes, etc..

lut = rev(rainbow(100, start=rgb2hsv(col2rgb('red'))[1], end=rgb2hsv(col2rgb('blue'))[1]))
color.bar(lut, -0.1, 0.1)

statistics/color-bars.txt · Last modified: 2011/05/27 10:44 am PDT by John Colby
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki