title: R pheatmap: change annotation colors and prevent graphics window from popping up
body: <p>Following up on <a href="https://stackoverflow.com/questions/41608294/r-heatmap-2-manual-grouping-of-rows-and-columns">this question</a>, I found the pheatmap function (which offers me a lot more control on the stuff that I want to do than heatmap.2).</p>
  
  <p>I have 2 problems though:</p>
  
  <p>1- I cannot change the colors of the annotation (categories)</p>
  
  <p>2- The graphics window keeps popping up even when I am saving the output in a png file</p>
  
  <p>This is my MWE:</p>
  
  <pre><code>library(pheatmap)
  library(RColorBrewer)
  cols &lt;- colorRampPalette(brewer.pal(9, "Set1"))
  
  mymat &lt;- matrix(rexp(600, rate=.1), ncol=12)
  colnames(mymat) &lt;- c(rep("treatment_1", 3), rep("treatment_2", 3), rep("treatment_3", 3), rep("treatment_4", 3))
  rownames(mymat) &lt;- paste("gene", 1:dim(mymat)[1], sep="_")
  
  annotdf &lt;- data.frame(row.names = paste("gene", 1:dim(mymat)[1], sep="_"), category = c(rep("CATEGORY_1", 10), rep("CATEGORY_2", 10), rep("CATEGORY_3", 10), rep("CATEGORY_4", 10), rep("CATEGORY_5", 10)))
  
  mycolors &lt;- cols(length(unique(annotdf$category)))
  names(mycolors) &lt;- unique(annotdf$category)
  mycolors &lt;- list(mycolors = mycolors)
  
  pheatmap(mymat,
       color=greenred(75),
       scale="row",
       cluster_rows = FALSE,
       cluster_cols = FALSE,
       gaps_row=c(10,20,30,40),
       gaps_col=c(3,6,9),
       cellheight = 6,
       cellwidth = 20,
       border_color=NA,
       fontsize_row = 6,
       main="Genes grouped by categories",
       filename = "TEST.png",
       annotation_row = annotdf,
       annotation_colors = mycolors
  )
  </code></pre>
  
  <p>Which produces:</p>
  
  <p><a href="https://i.stack.imgur.com/qaEva.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qaEva.png" alt="TEST"></a></p>
  
  <p>As you can see, the colors are clearly NOT the Set1 palette I specify, but the default pheatmap colors (you will get the same results removing the annotation_colors line).</p>
  
  <p><a href="https://i.stack.imgur.com/h38qQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/h38qQ.png" alt="colors"></a></p>
  
  <p>So my question here is: How do I specify annotation_colors in pheatmap??</p>
  
  <p>On the other hand, even when I am saving the pheatmap output in a png file, the graphics window keeps popping up, how do I prevent this from happening?</p>
  
  <p>Thanks! </p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.3.1 (2016-06-21)
  Platform: x86_64-pc-linux-gnu (64-bit)
  Running under: Ubuntu 16.04.1 LTS
  
  locale:
   [1] LC_CTYPE=en_SG.UTF-8       LC_NUMERIC=C              
   [3] LC_TIME=en_SG.UTF-8        LC_COLLATE=en_SG.UTF-8    
   [5] LC_MONETARY=en_SG.UTF-8    LC_MESSAGES=en_SG.UTF-8   
   [7] LC_PAPER=en_SG.UTF-8       LC_NAME=C                 
   [9] LC_ADDRESS=C               LC_TELEPHONE=C            
  [11] LC_MEASUREMENT=en_SG.UTF-8 LC_IDENTIFICATION=C       
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] gplots_3.0.1       RColorBrewer_1.1-2 pheatmap_1.0.8    
  
  loaded via a namespace (and not attached):
   [1] compiler_3.3.1     colorspace_1.2-6   scales_0.4.0       plyr_1.8.3        
   [5] tools_3.3.1        gtable_0.2.0       Rcpp_0.12.7        KernSmooth_2.23-15
   [9] gdata_2.17.0       grid_3.3.1         caTools_1.17.1     bitops_1.0-6      
  [13] munsell_0.4.3      gtools_3.5.0
  </code></pre>