raivokolde / pheatmap

Pretty heatmaps
227 stars 83 forks source link

cluster_distance_cols="correlation" produces different relationships from cluster_distance_cols=dist(1-cor(mat)) #41

Closed mebbert closed 6 years ago

mebbert commented 6 years ago

Hi,

I've been playing with pheatmap (wonderful package). I may be missing something very basic, but I noticed that the clusters produced by cluster_distance_cols="correlation" and cluster_distance_cols=dist(1-cor(mat)) are quite different. Shouldn't they be identical? It's not that the clades are simply rotated.

I can send you example images by email, but I'd prefer not to post them publicly because the data are sensitive.

Here are the two commands:

pheatmap(sig.heat,
         clustering_distance_rows="correlation",
         clustering_distance_cols="correlation",
         clustering_method="complete",
         cluster_cols = TRUE,
         cluster_rows = TRUE,
         show_rownames = FALSE,
         show_colnames = FALSE,
         fontsize_row = row.fontsize,
         fontsize_col = col.fontsize,
         fontsize = fontsize,
         annotation_col=sig.df
         )
pheatmap(sig.heat,
         clustering_distance_rows="correlation",
         clustering_distance_cols=dist(1-cor(sig.heat)),
         clustering_method="complete",
         cluster_cols = TRUE,
         cluster_rows = TRUE,
         show_rownames = FALSE,
         show_colnames = FALSE,
         fontsize_row = row.fontsize,
         fontsize_col = col.fontsize,
         fontsize = fontsize,
         annotation_col=sig.df
         )

EDIT: I'm using pheatmap version 1.0.8 and R version 3.4.3

fouslim commented 6 years ago

try cluster_distance_cols=as.dist(1-cor(mat)), it should solve your problem

mebbert commented 6 years ago

You were right. I guess dist(1-cor(sig.heat)) was calculating a distance of distances.

Shouldn't the same modification also be applied to #28? @raivokolde specified dist when describing how to use Spearman and Kendall.

fouslim commented 6 years ago

your are correct, in #28 as.dist() should be used instead of dist(). good catch.