Splitting heatmap
0
0
Entering edit mode
11 months ago

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 • 1.1k views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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")
ADD REPLY
0
Entering edit mode

let me check what I am doing wrong..!!

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2813 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6