superheat icon indicating copy to clipboard operation
superheat copied to clipboard

Allow distance matrix input

Open talegari opened this issue 7 years ago • 5 comments

Hi Rebecca,

Thanks for the handy package!

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

talegari avatar Oct 25 '17 08:10 talegari

Can you elaborate a little more on what you mean?

rlbarter avatar Oct 25 '17 16:10 rlbarter

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.

talegari avatar Oct 26 '17 04:10 talegari

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

rlbarter avatar Oct 31 '17 21:10 rlbarter

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

talegari avatar Nov 01 '17 05:11 talegari

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.

rlbarter avatar Nov 02 '17 16:11 rlbarter