Answers.Body: <p>You just need to add more colors. The following, for example, will work:</p>
  
  <pre><code>heatmap.2(d_matrix, scale="none", trace="none", Rowv=F, Colv=F, breaks=seq(0,1,0.01), dendrogram="none", col=redblue(100))
  </code></pre>
  
  <p>Note that <code>length(seq(0, 1, 0.01))</code> is 101, therefore <code>redblue()</code> must return one fewer (100) colors (or colours if you prefer extra vowels).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-15T16:24:24.163Z
Answers.Text: This worked. I have 2 more issues. I am having some sky blue lines in the color key which I don't want and secondly my rownames a and b are very big. Is there a way to reduce the size?? Thanks
Answers.UserDisplayName: user3138373
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-14T23:44:45.513Z
Answers.LastActivityDate: 2017-12-14T23:44:45.513Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I have a tab separated text file as shown below</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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</p>
  
  <p>Following is my code:</p>
  
  <pre><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)
  </code></pre>
  
  <p>But this gives me error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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</p>
  
  <p>I added breaks argument to the heatmap.2 function as suggested from this post <a href="https://stackoverflow.com/questions/17820143/how-to-change-heatmap-2-color-range-in-r">here</a> but no luck..</p>
  
Tags: <r><bioconductor>
Title: changing color key range to specified range in heatmap.2 function
ThreadText: # changing color key range to specified range in heatmap.2 function
  
  (Asked by: username_0 on 2017-12-14)
  
  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 <- read.table("file.txt",sep="\t",header=F,row.names = 1)     
  colnames(d) <- c("-3","-2","-1","+1","+2","+3","+4","+5","+6")
  d_matrix <- data.matrix(d)
  colors<-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](https://stackoverflow.com/questions/17820143/how-to-change-heatmap-2-color-range-in-r) but no luck..
  
  **Tags:** r, bioconductor
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-12-14. Score: 4 | Accepted answer
  
  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).
  
  > **Comments:**
  > **username_0**: This worked. I have 2 more issues. I am having some sky blue lines in the color key which I don't want and secondly my rownames a and b are very big. Is there a way to reduce the size?? Thanks  
  
  ---
  
  