changing color key range to specified range in heatmap.2 function I have a tab separated text file as shown below

a   0.311   0.510   0.123   0.002   0.001   0.417   0.572   0.074   0.169
b   0.324   0.592   0.070   0.028   0.028   0.535   0.535   0.127   0.113


I am trying to use heatmap.2 function from gplots package and want to change the color key so that it ranges from 0 to 1

Following is my code:

d &lt;- read.table("file.txt",sep="\t",header=F,row.names = 1)     
colnames(d) &lt;- c("-3","-2","-1","+1","+2","+3","+4","+5","+6")
d_matrix &lt;- data.matrix(d)
colors&lt;-seq(0,1,length.out=100)
heatmap.2(d_matrix,scale="none",col = redblue(75),trace="none",Colv = FALSE,Rowv = FALSE,breaks=colors)


But this gives me error:

Error in image.default(1:nc, 1:nr, x, xlim = 0.5 + c(0, nc), ylim = 0.5 +  : 
  must have one more break than colour


I want to change to color key such that it ranges from 0 to 1. How can I do it in the function heatmap.2

I added breaks argument to the heatmap.2 function as suggested from this post here but no luck..
You just need to add more colors. The following, for example, will work:

heatmap.2(d_matrix, scale="none", trace="none", Rowv=F, Colv=F, breaks=seq(0,1,0.01), dendrogram="none", col=redblue(100))


Note that length(seq(0, 1, 0.01)) is 101, therefore redblue() must return one fewer (100) colors (or colours if you prefer extra vowels).