Skip to content

Instantly share code, notes, and snippets.

@dustincys
Created January 20, 2014 12:45
Show Gist options
  • Save dustincys/8519325 to your computer and use it in GitHub Desktop.
Save dustincys/8519325 to your computer and use it in GitHub Desktop.
color.bar <- function(
lut, min, max=-min, nticks=11,
ticks=seq(min, max, len=nticks), title='',cexv=0.5
)
{
min<-as.integer(min);
max<-as.integer(max)+1;
scale = (length(lut)-1)/(max-min)
#dev.new(width=1.75, height=5)
plot(
c(0,11), c(min,max),
type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='acc',
main=title)
axis(2, ticks, las=1,cex.axis=cexv)
for (i in 1:(length(lut)-1)) {
y = (i-1)/scale + min
rect(0,y,10,y+1/scale, col=lut[i], border=lut[i])
}
lines(c(0,10,10,0,0),c(min-1/scale,min-1/scale,
(length(lut)-1)/scale+min+1/scale,(length(lut)-1)/scale+min+1/scale,min-1/scale))
rect(0,min-1/scale,10,min, col="black", border=NA)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment