Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heatmaply and heatmap.2 dendrograms don't seem to match when scaling is used #245

Open
simonroome opened this issue Jul 3, 2020 · 1 comment

Comments

@simonroome
Copy link

Thank you again for the great package.

I was having trouble getting the heatmaply dendrograms to match the heatmap.2 dendrogram, when I came across the heatmaply vignette directions to make them match. It seemed to work when scaling wasn't applied, but when I tried to apply row or column scaling, they no longer matched. Applying the scaling didn't seem to change the heatmap.2 dendrogram, but it did change the heatmaply dendrogram.

I made a quick shiny app to show the behaviour I'm getting with the scaling.

library(shiny)

ui <- fluidPage(
  plotlyOutput("heatmap"),
  plotOutput("heatmap2", height = "1000px")
)

server <- function(input, output, session) {
  
  x  <- as.matrix(datasets::mtcars)

  output$heatmap <- renderPlotly({
    heatmaply(x,

#### setting scale to "column" here instead of "none" causes the dendrogram to change for heatmaply

              scale = "column",
              seriate = "mean",
              row_dend_left = T,
              plot_method = "plotly")
  })
  output$heatmap2 <- renderPlot({
    heatmap(x,

#### setting scale to "column" here instead of "none" doesn't seem to change the dendrogram in heatmap.2
#### so if both heatmaply and heatmap.2 are set to "column", only the heatmaply dendrogram changes and 
#### they no longer match

              scale = "column", 
              trace = "none",
              col = viridis(100),
              key = T)
  })
}

shinyApp(ui, server)

I would expect that since the settings selected are those that in the vignette made heatmaply and heatmap.2 dendrograms match for non-scaled data, that the dendrograms would also match when you apply column scaling to both. There might be a very simple explanation for this that I'm missing or misunderstanding. I'm not sure if this is expected behaviour and if it might be better to post this on StackOverflow or if it is unexpected and this is the appropriate place to post this - if it's expected I apologize.

@simonroome simonroome added the bug label Jul 3, 2020
@alanocallaghan
Copy link
Collaborator

Scaling in heatmap.2 is applied after calculating dendrograms, in heatmaply scaling happens before. I prefer the heatmaply behaviour as otherwise there's a mismatch in the data and clustering. You can get the heatmap.2 behaviour by calculating dendrograms on raw data and passing them in while specifying the desire scale setting

@alanocallaghan alanocallaghan removed the bug label Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants