This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Splitting heatmap

have created a heatmap in R using heatmaply library which has 85 rows and 6 columns (samples). Is there ant possible way I could split my heatmap html file to indivdual sample heatmap ? I just want to view them separatly in an html file. I tried spliting the data using following code.

    # Loop over each sample and create a separate plot for each one
for (sample in colnames(data)) {
  # Subset the data to only include the current sample
  sample_data <- data[, sample, drop = FALSE]

  # Create the plot and save as an HTML file
  p <- heatmaply(sample_data, dendrogram = "both", scale = "row",
                 colorscale = "Viridis", margins = c(80, 80),
                 main = paste0("Heatmap for ", sample))
  html_file <- paste0(sample, ".html")
  saveWidget(as.widget(p), file = html_file, selfcontained = TRUE)
}

but gives the error for hclust function. is there a wayout ?

I want to split my html file into multiple html file containing only the information of single sample each.

r

I don't use this package, but hclust probably fails because you are only inputting one sample, so nothing can be clustered. Try setting the parameter dendrogram = "none" to disable clustering and see if it works.

tried that too. looks like hclust function is mandatory in heatmap

Really? try this code, this works for me:

library(heatmaply)

mt <- matrix(1:12,4,3)

heatmaply(mt, dendrogram = "none")
heatmaply(as.data.frame(mt[,1]), dendrogram = "none")

Are you getting a different type of error? for example, if you set dendrogram = "none" I think you should remove the scale = "row" command.

0 answers

No answers yet.

Log in to answer this question.