Is there a way to specify number of kmeans clusters to return in heatmaply

267 Views Asked by At

I would like to return a specific number of clusters for my interactive heatmap from heatmaply like I can do with pheatmap and the kmeans_k = argument. Is there a way to do this with heatmaply?

If I have a large matrix and do not define the number of clusters to return with heatmaply, it takes too long to calculate the heatmap or I will get the error: 'vector memory exhausted(limit reached?)'.

library(pheatmap)
data(mtcars)
mat <- as.matrix(mtcars)

pheatmap(
  mtcars,
  border_color = "grey20",
  main = "",
  show_rownames = TRUE,
  show_colnames = TRUE,
  kmeans_k = 30,
  cluster_rows = F,
  cluster_cols = F
)
1

There are 1 best solutions below

0
On

You want to use the k_col, and or k_row arguments.

You can see examples in the vignette, but just a simple example:

library("heatmaply")
heatmaply(mtcars, k_col = 2, k_row = 4)

Output:

enter image description here