Reputation: 833
I am trying to get 5 lists of all row elements after using heatmaply in R. I set k_row = 5 so the dendrogram shows 5 different colors. I just want to return a list of 5 lists, where each list contains the row elements within a cluster. The rows are names and the columns are categories.
Upvotes: 2
Views: 1272
Reputation: 51
You can get the clusters directly from the dendrogram of the same data. For example:
heatmap = heatmaply(mtcars, k_row = 3,
dist_method = "euclidean", hclust_method ="complete")
To get the row clusters from the same data:
dend <- hclust(dist(mtcars, method = "euclidean"), method = "complete")
cutree(dend, k = 3)
The cutree command will return the assignment for each row in the dataset. You'll notice they are the same size as the ones found in the heatmap. This is the same command heatmaply runs to color the clusters.
Upvotes: 5