You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I am new to dendextend so I hope this is not just a silly mistake, but I am trying to set the internal node labels (the branch labels?) of a dendrogram. When I get the label attributes, those seem to be included. But when I set the label attributes, it only seems to change the leaf labels.
To Reproduce
set.seed(1)
d <- as.dendrogram(hclust(dist(matrix(sample(1:10,50,T),5,dimnames = list(LETTERS[1:5])))))
plot(d) # a simple dendrograms with leaves labelled by capital letters
my.labs <- get_nodes_attr(dend = d, attribute = "label", include_leaves = T, include_branches = T)
my.labs # includes NA's which corresping to the branch node labels
# [1] NA NA "A" "C" NA "E" NA "B" "D"
my.labs[is.na(my.labs)] <- paste0("b", 1:length(my.labs[is.na(my.labs)]))
my.labs # same order as before but with b1, b2, b3 added for the branch labels
# [1] "b1" "b2" "A" "C" "b3" "E" "b4" "B" "D"
d <- dendextend::set(dend = d, what = "labels", value = my.labs)
get_nodes_attr(dend = d, attribute = "label", include_leaves = T, include_branches = T) # still has NA for internal node labels and has renamed leaf labels with the first part of the my.labs vector
# [1] NA NA "b1" "b2" NA "A" NA "C" "b3"
plot(d) # and can see that new branch b1 etc labels are mixed in to the leaf labels
Expected behavior
I expected get_nodes_attr(attribute = "label") to be like the inverse of set(what = "labels").
Additional context
I thought that by setting these internal node labels I would be able to use them as the id as in get_nodes_attr(dend = d, attribute = "label", id = "b1") but maybe I am also misunderstanding what ID means here.
Thank you for supporting this great package!
Robin
The text was updated successfully, but these errors were encountered:
Although the label and labels not matching is still a little confusing, I understand what's going on now and I don't think it's a bug- changing this issue to "enhancement" request.
Seems like dendextend is a convenient wrapper for setting dendrogram attributes in baseR, and it just doesn't include all possible attributes, just the most popular ones :) So it doesn't include edgetext (ie the branch labels) as a possible attribute in set(what = ), and these are a separate base attribute from label which every node could have. It's confusing because plot() will display only leaf labels and branch text, not internal node labels.
So without dendextend you could do this manually, one at a time or to a bunch of nodes with dendrapply:
attr(x = d[[1]], which = "edgetext") <- "branch label"
plot(d)
It would be cool if dendextend could adjust this conveniently too! These branch labels seem handy for annotating visualizations and the basic plot function recognizes them.
p.s. I also mentioned id but I realize now that id= is only numeric- it seems like unlike lists dendrograms cannot have named elements, and any names are only label attributes and can't be used to subset nodes.
Describe the bug
I am new to dendextend so I hope this is not just a silly mistake, but I am trying to set the internal node labels (the branch labels?) of a dendrogram. When I get the label attributes, those seem to be included. But when I set the label attributes, it only seems to change the leaf labels.
To Reproduce
Expected behavior
I expected
get_nodes_attr(attribute = "label")
to be like the inverse ofset(what = "labels")
.Additional context
I thought that by setting these internal node labels I would be able to use them as the id as in
get_nodes_attr(dend = d, attribute = "label", id = "b1")
but maybe I am also misunderstanding what ID means here.Thank you for supporting this great package!
Robin
The text was updated successfully, but these errors were encountered: