Questions tagged [dendextend]

Questions on the R package dendextend

The dendextend R package includes functions and methods for extending dendrogram objects in R (visualization, manipulation and comparison).

158 questions
4
votes
2 answers

Change leaf color in plot.dendrogram like with plot.phylo of package ape

I am trying to plot the result of agglomerative clustering (UPGMA with Agnes) in the same 'style' as when plotting a tree using the package 'ape'. A simple example I include in the figure below The key issue is that I want to be able to color the…
FM Kerckhof
  • 1,270
  • 1
  • 14
  • 31
3
votes
1 answer

Is there a way to extract the height from each leaf of a dendrogram in R?

enter image description here From this dendrogram, I would like to extract the height for each leaf. In this case example, I would like to get back a list like this : list("A" = 2.07, "B" = 5.09, "C" = 3.12, "D" = 2.07, "E" = 3.12) Here's the code…
3
votes
1 answer

Combining a ggdend tree with a geom_scatterpie

I have a phylogenetic tree: my.tree <- ape::read.tree(text = "((rat:0.06290316531,mouse:0.06094803666):0.05175420892,human:0.09883650566);") which I then convert to a ggdend object: library(dplyr) my.dend <- phylogram::as.dendrogram.phylo(my.tree)…
dan
  • 6,048
  • 10
  • 57
  • 125
3
votes
1 answer

Divergence between cutree and cluster branches

I have a data set consisting of the daily water intake for some mice belonging to 4 different genotypes. I am trying to write a script in order to classify these animals according to their pattern of water intake using a hierarchical cluster…
3
votes
3 answers

How to color branches in R dendogram as a function of the classes in it?

I wish to visualize how well a clustering algorithm is doing (with certain distance metric). I have samples and their corresponding classes. To visualize, I cluster and I wish to color the branches of a dendrogram by the items in the cluster. The…
borgr
  • 20,175
  • 6
  • 25
  • 35
3
votes
0 answers

Plot cut dendrogram with class labels

In the following example: hc <- hclust(dist(mtcars)) hcd <- as.dendrogram((hc)) hcut4 <- cutree(hc,h=200) class(hcut4) plot(hcd,ylim=c(190,450)) I'd like to add the labels of the classes. I can do: hcd4 <- cut(hcd,h=200)$upper plot(hcd4) Besides…
user2955884
  • 405
  • 2
  • 11
3
votes
2 answers

How to change the color of dendrogram for each group in a cluster

Here is my data df<- structure(list(name = structure(c(2L, 12L, 1L, 16L, 14L, 10L, 9L, 5L, 15L, 4L, 8L, 13L, 7L, 6L, 3L, 11L), .Label = c("All", "Bab", "boro", "bra", "charli", "delta", "few", "hora", "Howe", "ist", "kind", "Kiss", "myr", "No",…
nik
  • 2,500
  • 5
  • 21
  • 48
3
votes
1 answer

R and rect.hclust: rectangle on labels in dendrograms

I am building a dendrogram for the first time and the rectangles around clusters are drawn on top of the labels. Do you know how modify the positioning of these labels in order to avoid this overlap? Here you can find a working example of my…
atalantafugiens
  • 423
  • 6
  • 16
3
votes
1 answer

Color dendrogram branches based on external labels uptowards the root until the label matches

From question Color branches of dendrogram using an existing column, I can color the branches near the leaf of the dendrogram. The code: x<-1:100 dim(x)<-c(10,10) set.seed(1) groups<-c("red","red", "red", "red", "blue", "blue", "blue","blue", "red",…
discipulus
  • 2,665
  • 3
  • 34
  • 51
3
votes
2 answers

Annotate the distance on nodes of a dendrograms

Consider a simple dendrogram like dend <- 1:5 %>% dist %>% hclust %>% as.dendrogram How can I annotate the distance (height) on the nodes? I looked up the dendextend package but it does not offer such a feature. However, I know I can the list of…
Sepehr
  • 442
  • 1
  • 6
  • 17
3
votes
1 answer

hclust() with cutree...how to plot the cutree() cluster in single hclust()

I clustered my hclust() tree into several groups with cutree(). Now I want a function to hclust() the several groupmembers as a hclust()... ALSO: I cut one tree into 168 groups and I want 168 hclust() trees... My data is a 1600*1600 matrix. My data…
Mareaky
  • 31
  • 1
  • 1
  • 2
3
votes
1 answer

R plot upper dendrogram based on k

I am clustering a distance matrix based on a 20,000 row x 169 column data set in R using hclust(). When I convert the cluster object to a dendrogram and plot the entire dendrogram, it is difficult to read because it is so large, even if I output it…
3
votes
1 answer

How can I add colored_bars to a dendextend plot where I set horiz=T

I understand how to add colored bars to a dendextend plot, but when I set horiz=T the bar is plotted on the wrong axis. The example from the Introduction to dendextend shows how to add colored bars to a plot: dend15 <- c(1:5) %>% dist %>%…
3
votes
1 answer

display clusters in radial format

I have a list of clusters lets say from cluster 1 to cluster 3; along with their membership for example below. I would like to display the clusters in radial format. I was thinking of using the as.phylo function in the ape package to display this,…
qfd
  • 778
  • 2
  • 10
  • 24
3
votes
3 answers

Coloring dendrogram’s end branches (or leaves) based on column number of data frame in R

From a dataframe data.main, I am able to generate a hclust dendrogram as, aa1<- c(2,4,6,8) bb1<- c(1,3,7,11) aa2<-c(3,6,9,12) bb2<-c(3,5,7,9) data.main<- data.frame(aa1,bb1,aa2,bb2) d1<-dist(t(data.main)) hcl1<- hclust(d1) plot(hcl1) Further, I…
Polar.Ice
  • 138
  • 2
  • 12
1 2
3
10 11