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
Apply customized dendrogram to heatmap #305
Comments
Hi, can you send me all these R objects that you use in your code (e.g. |
Hi, I'm experiencing a similiar (if not the same) problem here. mat <- matrix(c(5, 2.28, 2.06, -3.53,-3.53,-3.53, -5,-3,-2.3,3,3.82, 3.82,-5,-2.36,-3.23,3.82,-3.53,-3.53, -5,-1.15,-2,0, 0.92,-0.92, -5,-2.54,-2.30,0, -3.53,-3.53,5,3, 2.37, -3.53, -3.53,-3.53), nrow = 6, ncol = 6, byrow = T, dimnames = list(paste0("row_",c("A","B","C","D","E","F")), paste0("col_",c("A","B","C","D","E","F")))) #reorder the dendrogram with rotate from dendextend package plot(column_dend) cluster_columns = column_dend ht1 <- Heatmap(mat, cluster_rows = F, cluster_columns = cluster_columns, show_heatmap_legend = TRUE) draw(ht1, heatmap_legend_side = "top") Here I was expecting in the heatmap the same column order as in plot(column_dend). Thanks very much for the help. |
@GScala I tried your code and they look the same: Maybe you need to try the newest version of the package, or at least >= 1.99.0 |
Hi, |
hi @jokergoo , I cannot get this to work. My situation: I have a matrix composed of m rows (assume they're strains) and n columns (assume they're genes). Assume I have gene presence absence data for samples (m x n matrix). Assume also that I have a clustering (dendrogram) of strains (m) based on another dataset than the gene absence/presence matrix. Assume that for the genes (n) I have a separate clustering (dendrogram) too, generated using by a third, separate dataset (e.g. gene similarity). First I sort the matrix I want to plot as a heatmap based on the dendrogram labels
The gene presence/absence data where the rows and columns sorted with respect to the order in the dendrograms mentioned above looks like this
When I include the dendrograms in the plot:
I get a dendrogram where the columns and rows are sorted differently (note that the first now now is ST-182 and the last row is ST-247) so the dendrograms are correctly plotted, but the order of rows and columns are wrong, resulting in a different heatmap than the first one. Is there a way I can plot the dendrograms and still get the first heatmap? |
In the first heatmap, you didn't apply clustering, and in the second heatmap, you applied clustering. Clustering changes the row orders and columns. It is expected the order your rows change accordingly. |
@jokergoo I don't get it. In the first heatmap above, the rows and columns are pre-sorted based on the order of labels of the dendrograms plotted in the second heatmap (see the variables In the second heatmap where the dendrograms are plotted, although the dendrograms themselves are plotted correctly, the order of rows and columns shown don't match the order obtained by
and therefore the clusters in the first heatmap aren't observed anymore. I don't think this is expected behavior? |
Hi @jokergoo,
I'd appreciate any help. Thanks! |
@alimayy sorry I didn't read your replies carefully. In your code: ComplexHeatmap::Heatmap(as.matrix(mat_to_plot),
show_row_names = T,
show_column_names = F,
cluster_columns = as.dendrogram(gene_clustering_based_on_prank_alignment),
cluster_rows = as.dendrogram(sample_hclust_clustering),
name="Phage-host interactions",
col = colorRampPalette(c('black', 'green'))(2),
show_column_dend = T,
show_row_dend = T )
If you want the same plot as the first one, you need to use the original Heamtap(mydataframe, ..., row_dend_reorder = FALSE, column_dend_reorder = FALSE) |
@metalichen ComplexHeatmap mainly works with the dendrogram object and I haven't tested with other tree objects such |
@jokergoo sorry, should have specified - my I attached the matrix, and the dendrogram, as a Newick file. Thanks! |
@metalichen Do you use |
@jokergoo I used
|
There are several points when using phylo objects that need to be taken care of:
If the correspondance is correct, There are several ways I can think of to support phylo objects:
Once I finish these implementations, I will let you know. |
makes sense! thanks |
That worked, thanks @jokergoo ! |
Hey,
I was wondering how to apply my customized dendrogram to the heatmap. I first generated a heatmap with specified clustering method in Heatmap commend:
Heatmap(matrix_new, cluster_columns =T, cluster_rows=F, clustering_distance_columns = "pearson", clustering_method_columns = "ward.D")
Then, I customized the dendrogram using the following codes
hc <- hclust(as.dist(1-cor(t(sample.norm[,1:18]),method="pearson")),method="ward.D")
dd <- as.dendrogram(hc)
dd.reorder = reorder(dd, c(rep(10, 22),rep(9,27),rep(1,49)), agglo.FUN = mean)
When I plot the customized dendrogram, it did changed into the way I want. And I assigned the customized dendrogram to the heatmap I created at the first:
Heatmap(matrix_new, cluster_columns = dd.reorder, cluster_rows=F)
However, the dendrograms in two heatmaps did not change. I am not sure what went wrong, and come here for some help. Any advise?
Thanks,
Stingo
The text was updated successfully, but these errors were encountered: