talgalili / dendextend

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

branches_attr_by_labels 'type' options #40

Open MaximilianStammnitz opened 7 years ago

MaximilianStammnitz commented 7 years ago

Hi,

I have only recently started using the various dendextend features, and haven't yet come across something that I think would be useful for some users' applications:

When adjusting col, lwd or lty in branches_attr_by_labels; could you possibly add more flexibility as to how close to the root these features shall reach? I.e., allowing for the 'type' options in branches_attr_by_labels between 'all' and 'any' to also take an integer input that indicates the number of nodes away from the root until which the branch adjustment shall act?

This may enable highlighting of distances between leaves/clusters in a given dendrogram that don't connect through the root.

Best regards, Max

talgalili commented 7 years ago

Hi Max, Are you referring to something like highlight_branches?

dat <- iris[1:20,-5]
hca <- hclust(dist(dat))
hca2 <- hclust(dist(dat), method = "single")
dend <- as.dendrogram(hca)
dend2 <- as.dendrogram(hca2)

par(mfrow = c(1,3))
dend %>% highlight_branches_col %>% plot(main = "Coloring branches")
dend %>% highlight_branches_lwd %>% plot(main = "Emphasizing line-width")
dend %>% highlight_branches %>% plot(main = "Emphasizing color\n and line-width")

image

Or something else?

MaximilianStammnitz commented 7 years ago

Hi Tal,

I was thinking of an example like this one: example_case

Ideally, you should be able to opt out of highlighting the branches between root and MRCA.

talgalili commented 7 years ago

Hi @MaximilianStammnitz This looks very doable, but I won't get the time in the near future to write it up. You want to have a go at it? (if so - I'll be happy for a pull request)

MaximilianStammnitz commented 7 years ago

Hi @talgalili, I will probably get to this in the coming week.