I have a data frame of omics data. Gene ids in rows (931), and samples in columns (15).

    > dim(my_data) # (rows columns)
    [1] 931  16

I created heatmap using `library(gplots)`

    cn=colnames(gdf1)[c(13:15,1:12)]
    
    col <- colorRampPalette(c("red","yellow","darkgreen"))(30)
    
    heatmap.2(as.matrix(gdf1[,cn]), 
              dendrogram = "row", 
              Colv = FALSE, 
              Rowv = TRUE,
              scale = "none", 
              col = col,
              key = TRUE, 
              density.info = "none", 
              key.title = NA, 
              key.xlab = "Abundance",
              trace = "none",
              margins = c(7, 15))

<a href="https://ibb.co/C94gqgF"><img src="https://i.ibb.co/3FV2w2H/Rplot03.png" alt="Rplot03" border="0"></a><br />

However, in the heatmap, I see only few genes. Since it has 900 ish genes. How can I export what are the clustered genes in each cluster in the same order as in the heatmap?


Also, how can I reduce the size of colorkey?

Thank you.

**Edit 13th September, 2019:**
To additionally see how to extract clusters of genes from the heatmap dendrogram, zoom down to this later comment: https://www.biostars.org/p/398548/#398618

---------------
---------------

Hello,

First, create random data
----

    mat <- matrix(rexp(200, rate=.1), ncol=20)
    rownames(mat) <- paste0('gene',1:nrow(mat))
    colnames(mat) <- paste0('sample',1:ncol(mat))
    mat[1:5,1:5]
             sample1   sample2   sample3   sample4     sample5
    gene1  0.6247039  3.020142  8.303563  6.482744  0.59547154
    gene2  2.6650871  3.375123  5.778222 19.410709  0.07966728
    gene3  4.6343755  5.491166  8.716883  9.490372 29.03157875
    gene4 13.6086878  3.632815 10.688699  1.263853  2.54216953
    gene5  2.4060078 14.283380  8.592085  3.998141  0.25853135

Generate a heatmap and save it to `out`
---

    out <- heatmap.2(mat)

<a href="https://ibb.co/nDQhSKW"><img src="https://i.ibb.co/dQknyHh/fff.png" alt="fff" border="0"></a>

Obtain list of genes, ordered as per heatmap (from bottom, up):
---

    rownames(mat)[out$rowInd]
     [1] "gene2"  "gene9"  "gene7"  "gene8"  "gene4"  "gene5"  "gene3"  "gene6" 
     [9] "gene1"  "gene10"

Plot the row dendrogram on its own:
------

    plot(out$rowDendrogram)

<a href="https://imgbb.com/"><img src="https://i.ibb.co/8MSKBsX/hhhhh.png" alt="hhhhh" border="0"></a>


Change colour key size
-------

Use `keysize` parameter

----------------------------------
-----------------

See also here for pheatmap: https://www.biostars.org/p/287512/#287518

Kevin