dendextend

How to create a dendrogram with colored branches?

微笑、不失礼 提交于 2019-12-17 09:54:03
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . I would like to create a dendrogram in R which has colored branches, like the one shown below. So far I used following commands to create a standard dendrogram: d <- dist(as.matrix(data[,29])) # find distance matrix hc <- hclust(d) # apply hirarchical clustering plot(hc,labels=data[,1], main="", xlab="") # plot the dendrogram How should I modify this code to obtain desired

Annotate the distance on nodes of a dendrograms

 ̄綄美尐妖づ 提交于 2019-12-12 17:19:07
问题 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 these distances from heights <- as.list(dend %>% get_nodes_attr("height")) Any help is highly appreciated. 回答1: Here's a simple example using hc2axes from the pvclust package: # install.packages("pvclust") # install package if needed plot(hc <- hclust

How to change dendrogram labels in r

安稳与你 提交于 2019-12-12 08:03:14
问题 I have a dendrogram in R. It is based on hierachical clustering using hclust. I am colouring labels that are different in different colours, but when I try changing the labels of my dedrogram (to the rows of the dataframe the cluster is based on) using dendrogram = dendrogram %>% set("labels", dataframe$column) the labels are replaced, but in the wrong positions. As example: My dendrogram looks like this: ___|___ | _|_ | | | | 1 0 2 when I now try changing the labels like specified above, the

selecting number of leaf nodes of dendrogram in heatmap.2 in R

孤街浪徒 提交于 2019-12-11 18:46:15
问题 In Matlab you can designate the number of nodes in a dendrogram that you wish to plot as part of the dendrogram function: dendrogram(tree,P) generates a dendrogram plot with no more than P leaf nodes. My attempts to do the same with heatmap2 in R have failed miserably. The posts to stackoverflow and biostars have suggested using cutree but heatmap2 gets stuck with postings' suggestions on Rowv option. Here "TAD" is the data matrix 8 columns by 831 rows. # cluster it hr <- hclust(dist(TAD,

Label R dendrogram branches with correct group number

邮差的信 提交于 2019-12-11 17:04:25
问题 I am trying to draw a dendrogram so that the labels on the branches match the group number from my cluster analysis. Currently the branches are simply labelled from left to right in the order that they appear, not the actual group number. Here is my current R code and resulting dendrogram: dst <- dist(Model_Results,method="binary") hca <- hclust(dst) clust <- cutree(hca,k=40) dend <-as.dendrogram(hca) library(dendextend) dend1 <- color_branches(dend, k = 40, groupLabels = TRUE) plot(dend1)

How to access attributes of a dendrogram in R

落花浮王杯 提交于 2019-12-11 09:11:28
问题 From a dendrogram which i created with hc<-hclust(kk) hcd<-as.dendrogram(hc) i picked a subbranch k=hcd[[2]][[2]][[2]][[2]][[2]][[2]][[2]][1] When i simply have k displayed, this gives: > k [[1]] [[1]][[1]] [1] 243 attr(,"label") [1] "NAfrica_002" attr(,"members") [1] 1 attr(,"height") [1] 0 attr(,"leaf") [1] TRUE [[1]][[2]] [1] 257 attr(,"label") [1] "NAfrica_016" attr(,"members") [1] 1 attr(,"height") [1] 0 attr(,"leaf") [1] TRUE attr(,"members") [1] 2 attr(,"midpoint") [1] 0.5 attr(,

How to create a dendrogram with colored branches?

这一生的挚爱 提交于 2019-12-11 07:59:13
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . I would like to create a dendrogram in R which has colored branches, like the one shown below. So far I used following commands to create a standard dendrogram: d <- dist(as.matrix(data[,29])) # find distance matrix hc <- hclust(d) # apply hirarchical clustering plot(hc,labels=data[,1], main="", xlab="") # plot the dendrogram How should I modify this code to obtain desired

r dendrogram - groupLabels not match real labels (package dendextend)

巧了我就是萌 提交于 2019-12-11 00:59:04
问题 Let's do a quick 3-clusters classification on the iris dataset with the FactoMineR package: library(FactoMineR) model <- HCPC(iris[,1:4], nb.clust = 3) summary(model$data.clust$clust) 1 2 3 50 62 38 We see that 50 observations are in cluster 1, 62 in cluster 2 and 38 in cluster 3. Now, we want to visualize these 3 clusters in a dendrogram, with the package dendextend which enables to make pretty ones: library(dendextend) library(dplyr) model$call$t$tree %>% as.dendrogram() %>% color_branches

Dendextend: Regarding how to color a dendrogram’s labels according to defined groups

六月ゝ 毕业季﹏ 提交于 2019-12-10 18:22:50
问题 I'm trying to use an awesome R-package named dendextend, to plot a dendrogram and color its branches & labels according to a set of previously defined groups. I've read your answers in Stack Overflow, and the FAQs of dendextend vignette, but I'm still not sure on how to achieve my goal. Let's imagine I have a dataframe with a first column with the names of the individual to use for the clustering, then several columns with the factors to be analyzed, and the last column with the group

Color side bar dendrogram plot

别说谁变了你拦得住时间么 提交于 2019-12-08 20:25:33
Initially I was trying to add the horizontal color side bar to the dendrogram plot (NOT to the whole heat map) using colored_bars from dendextend. The code below (THANK YOU for your help Tal!) works pretty well. The only issue remaining is how to control the distance of the bar from the leaves labels and the bar width? Here is an example, data and code Data (4 variables, 5 cases) df <- read.table(header=T, text="group class v1 v2 1 A 1 3.98 23.2 2 A 2 5.37 18.5 3 C 1 4.73 22.1 4 B 1 4.17 22.3 5 C 2 4.47 22.4 ") car_type <- factor(df[,c(1)]) # groups codes (A,B,C) cols_4 <- heat.colors(3) col