JWilli3
JWilli3

Reputation: 1

Labeling Row Names as Leaf Nodes Dendrogram Names in R

I am trying to Label my dendrogram using the designated Rownames from my dataset.

I am using the package: hybridHclust with the following code.

Sample Table (DATASET, I hope I am using the right format)

  UID Condition1 Condition2 Condition3
1 Gene1 0.46 0.47 -0.02
2 Gene2 0.8 0.93 0.08
3 Gene3 0.45 0.89 1.04

DATASET_1 <- DATASET[,-1] # removes UID column which is not needed
  Gene Condition1 Condition2 Condition3

Now I have removed the UID column which is needed for the origianl excel sheet but not for the cluster analysis:

  Condition1 Condition2 Condition3
1 0.46 0.47 -0.02
2 0.8 0.93 0.08
3 0.45 0.89 1.04

DATASETMatrix <- as.matrix.data.frame(DATASET_2) # converts df to matrix
DATASETMatrix_R <- t(DATASETMatrix) #flips along diagonal for clustering

Now the table is

             v1 v2 v3
Condition1 0.46 0.8 0.45
Condition2 0.47 0.93 0.89
Condition3 -0.02 0.08 1.04

And the row number designations (1, 2, 3) are gone in R studio and replaced with the listed conditions.

DATASETClust <- as.dendrogram((eisenCluster(DATASETMatrix_R, method = "uncentered.correlation",
                                        compatible = TRUE)), hang = -0.1) #uses uncentered Pearson correlation which is not present in hclust

library(dendextend)
DATASETClust %>% set("labels_cex", 0.25) %>% 
plot(horiz = T) # got his from somewhere online

enter image description here When I run this I get the Row numbers as the labels on my Dendrogram, but I need the Row names (Conition1, Condition2, Condition3) and they need to correspond to their respective data (should not just be in numerical order). This might not be so bad, but my actual dataset has more than 400 conditions being compared, with over 4000 variables each, and the list will continue to grow, so entering the names manually is not feasible.

Thank you all and I welcome feed back on any formatting issues when posting to this site.

Upvotes: 0

Views: 1402

Answers (1)

EugenR
EugenR

Reputation: 176

You could change the labels (names) of DATASETClust (an object of class dendrogram) using the package dendextend.

See an example of usage here

Upvotes: 1

Related Questions