Skip to content

Instantly share code, notes, and snippets.

@johncolby
Created May 26, 2011 19:16
Show Gist options
  • Save johncolby/993830 to your computer and use it in GitHub Desktop.
Save johncolby/993830 to your computer and use it in GitHub Desktop.
An R function to generate color bar legends for neuroimaging plots
# 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)
}
}
@johncolby
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment