Created
May 26, 2011 19:16
-
-
Save johncolby/993830 to your computer and use it in GitHub Desktop.
An R function to generate color bar legends for neuroimaging plots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to plot color bar | |
color.bar <- function(lut, min, max=-min, nticks=11, ticks=seq(min, max, len=nticks), title='') { | |
scale = (length(lut)-1)/(max-min) | |
dev.new(width=1.75, height=5) | |
plot(c(0,10), c(min,max), type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='', main=title) | |
axis(2, ticks, las=1) | |
for (i in 1:(length(lut)-1)) { | |
y = (i-1)/scale + min | |
rect(0,y,10,y+1/scale, col=lut[i], border=NA) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: http://www.colbyimaging.com/wiki/statistics/color-bars