rlbarter / superheat

An r package for generating beautiful and customizable heatmaps
https://rlbarter.github.io/superheat/
235 stars 29 forks source link

Allow distance matrix input #30

Open talegari opened 6 years ago

talegari commented 6 years ago

Hi Rebecca,

Thanks for the handy package!

Would it be a good idea to allow a distance matrix input?

rlbarter commented 6 years ago

Can you elaborate a little more on what you mean?

talegari commented 6 years ago

In some situations, we might have just distance matrices and not original data matrix. Visualizing heatmap of distance matrices and dendograms might be a good idea. Here is one illustration:

library("magrittr")
iris[,1:4] %>%  
  dist() %>%  # assume we only have dist, but not the original data matrix
  GMD::heatmap.3()

produces:

image

I find superheat's interface and plot(based on ggplot2) better. It might be handy to have an option to input a dist object.

rlbarter commented 6 years ago

I see what you're suggesting. At some point I might add this functionality, but at the moment doing this would only require one extra line converting the distance matrix to an actual matrix:

iris[,1:4] %>%  
  dist() %>% 
  as.matrix %>%
  superheat
talegari commented 6 years ago

You are missing the point: Hierarchical clustering of the data and data %>% dist() %>% as.matrix() yield two different dendograms. In the latter case, we are clustering based on distances of distances.

library("superheat")
library("magrittr")
library("cowplot")

with_dist <- iris[,1:4] %>%  
  dist() %>% 
  as.matrix() %>%
  superheat(row.dendrogram = TRUE, print.plot = FALSE) %>% 
  extract2("plot")

plain <- iris[,1:4] %>%  
  superheat(row.dendrogram = TRUE, print.plot = FALSE) %>% 
  extract2("plot")

cowplot::plot_grid(with_dist, plain)

produces:

image

rlbarter commented 6 years ago

Ah I see - so you want to provide the original dendrogram but plot the distance matrix.

I'll add this to my list of features to add... it might be a while before I get to it though. I have other priorities at the moment unfortunately.