#define a color scale
tones <- c("#99000D", "#FB6A4A", "white", "#6BAED6", "#084594")
multihue <- colorRampPalette(tones, space = "Lab")(101)
#create a two-panel figure with width ratio of 4:1
nf <- layout(matrix(c(1,1,1,1,2),2,5,byrow=TRUE))
layout.show(nf)
#mapping a matrix of randomly chosen numbers between -1 and 1 to
#colors in the color scale
h <- matrix(runif(100, -1, 1),10,10)
image(h,col=multihue,xaxt="n", yaxt="n")
#add color bar
par(mar=c(5,5,5,2))
colorBar(colpalette=multihue, min=-1,max=1)
Run the code above in your browser using DataLab