This is a post from [stackoverflow][1] here they show how to extract dedrogram such in form of respective cluster but this is with heatmap.2 function , i m trying to do the same with pheatmap , let's say a group of genes are forming clusters then i want to extract them 

Im doing something like this in my code but its giving me all of them togethter not cluster wise as seen in the heatmap 

    out = pheatmap(data, 
                   color=macolor,
                   
                   show_rownames = F,cluster_cols=T,cluster_rows=T, scale="row",
                   cex=1,clustering_distance_rows = "euclidean", cex=1,
                   clustering_distance_cols = "euclidean", clustering_method = "complete",border_color = FALSE)
    
    
    res <- data[c(out$tree_row[["order"]]),out$tree_col[["order"]]]

  [1]: https://stackoverflow.com/questions/28356354/write-table-with-row-name-ordered-after-clustering-in-rs-heatmap-2


any suggestion or help would be highly appreciated.

 

If you add an argument for "kmeans_k" in your pheatmap command, then you can use a very simple option, below:

    out = pheatmap(data, color=macolor, kmeans_k = 10, show_rownames = F,cluster_cols=T,cluster_rows=T, scale="row", cex=1,clustering_distance_rows = "euclidean", cex=1, clustering_distance_cols = "euclidean", clustering_method = "complete",border_color = FALSE)

    geneclusters <- out[["kmeans"]][["cluster"]]
    
    geneclusters[geneclusters==5]
    
    geneclusters[geneclusters==1]

etc.
