talgalili / dendextend

Extending R's Dendrogram Functionality
152 stars 28 forks source link

Is it possible to get labels info from the dendrogram object? #101

Open Jigyasa3 opened 4 years ago

Jigyasa3 commented 4 years ago

Hey!

Thank you for the interesting package! I am interested coloring the branches of a dendrogram. I am able to do so with the set() functions, but the colors are not according to the original tip.labels of the tree for which I have the color variable assigned.

What I have- ` phy.dist<-cophenetic(taxa_tree) dend<-phy.dist%>%as.dist()%>%hclust()%>%as.dendrogram()

cols<-as.character(lineage3$lineage_color)) #138 colors ordered according to the "taxa_tree". Taken from df "lineage2" that contains the metadata for the tree. head(cols) 301_19-AUS89-Kalotermitidae-Kalotermitidae_sp_A "#b8860b" 229_05-MD_RNA_1-Mastotermitidae-Mastotermesdarwiniensis "#b8860b" 229_08-Cryp-Cryptocercidae-Cryptocercus_punctulatus "#b8860b"

cols2<-(as.factor(lineage3$lineage_color)) #9 colors for 9 clades

dend%>%set("labels_cex",0.5)%>%set("labels_color",cols)%>%set("branches_col",cols2)%>%plot()`

image

Problem- The label colors do not match the labels in the dendrogram as the tree topology has changed when converting from phylo object to distance matrix. The branch colors are completely different too.

What I want- A dendrogram with branches colored by clades that corresponds to the original "taxa_tree"

talgalili commented 4 years ago

Your tree has many branches. The command set("branches_col",cols2) assumed you understand how to color each of the branches. In practice what you do is give much fewer colors than number of branches, leading to a recycling of the colors to yield "odd" results. You can color the tips/leaves or the labels with your colors. If you want to color the branches you'll need to use some of the other methods (such as color_branches), and the structure in the tree you show doesn't seem to correspond with the labels color you have.

Lastly, please refer such questions to stackoverflow.com with the tags r and dendextend. They do not belong here. Here is a place for bug reports and feature requests.

Cheers, T

On Fri, Jun 5, 2020 at 11:55 AM Jigyasa Arora notifications@github.com wrote:

Hey!

Thank you for the interesting package! I am interested coloring the branches of a dendrogram. I am able to do so with the set() functions, but the colors are not according to the original tip.labels of the tree for which I have the color variable assigned.

What I have- ` phy.dist<-cophenetic(taxa_tree) dend<-phy.dist%>%as.dist()%>%hclust()%>%as.dendrogram()

cols<-as.character(lineage3$lineage_color)) #138 colors ordered according to the "taxa_tree". Taken from df "lineage2" that contains the metadata for the tree. head(cols) 301_19-AUS89-Kalotermitidae-Kalotermitidae_sp_A "#b8860b" 229_05-MD_RNA_1-Mastotermitidae-Mastotermesdarwiniensis "#b8860b" 229_08-Cryp-Cryptocercidae-Cryptocercus_punctulatus "#b8860b"

cols2<-(as.factor(lineage3$lineage_color)) #9 https://github.com/talgalili/dendextend/issues/9 colors for 9 clades

dend%>%set("labels_cex",0.5)%>%set("labels_color",cols)%>%set("branches_col",cols2)%>%plot()`

[image: image] https://user-images.githubusercontent.com/21186292/83856542-abd25080-a754-11ea-933d-ed9f1316edee.png

Problem- The label colors do not match the labels in the dendrogram as the tree topology has changed when converting from phylo object to distance matrix. The branch colors are completely different too.

What I want- A dendrogram with branches colored by clades that corresponds to the original "taxa_tree"

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/talgalili/dendextend/issues/101, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBVBHL2RDCMFEXO5GL3RVCXHPANCNFSM4NTLOPYQ .