1

I have a large dataset composed of numerical observations. For this data set, I calculated k-means for which I defined 6 clusters. How can I draw a heatmap, of each cluster? When I try the following, I get an error:

clusters <- kmeans(dataset, 6) heatmap(clusters$cluster)

Zhannie
  • 177
  • 2
  • 5

1 Answers1

0

So basically, what you can do is to subset further, and use a for loop. The result of clusters is a list, in which centers, or k (clusters), are the sets of observations you specify in the kmeans function.

clusters <- kmeans(dataset, k = 6)
for (i in c(1:k)) {
pheatmap(dataset[names(clusters$cluster[clusters$cluster == i]), ])
}

Here, if k = 6, you get 6 heatmaps, one of each cluster of observations from your dataset.

Zhannie
  • 177
  • 2
  • 5