0

I have a dendogram of 150 genes imported in R, and I have a data frame with the same labels of the dendogram with score values from 0 to 200, that are independent from the dendogram.

I would like to colour the labels of the dendogram with the score values from the table using a gradient of colours from blue to red for example. I have found answers to similar questions at the following links How to colour the labels of a dendrogram by an additional factor variable in R & How to color a dendrogram's labels according to defined groups? (in R)

But I have not been able to work out how to convert the example codes for my code because:

1) none of them match the dendogram with an external value linked by the labels and
2) I would like to assign a colour depending on the score and not a random colour.

Here is the data example of my code

library(ape)
library(dendextend)

# Load tree
MyTree <- read.tree("species_tree.ph")

((raccoon:19.19959,bear:6.80041):0.84600,((sea_lion:11.99700, seal:12.00300):7.52973,((monkey:100.85930,cat:47.14069):20.59201, weasel:18.87953):2.09460):3.87382,dog:25.46154);

MyTree$root.edge <- 0                                       # Root the tree
MyTree=root(MyTree,"monkey",resolve.root = TRUE)
utree <- chronos(MyTree, lambda = 0, model = "correlated")  # Convert to ultrametric
dend=as.dendrogram(utree)                                   # Make dendogram
plot(dend)

# Load data of scores
scores <- read.csv("Scores_species.csv", header = TRUE, sep ="\t")

    Species Score
1  raccoon    97
2     bear    78
3 sea_lion    46
4     seal    14
5   monkey    57
6      cat    89
7   weasel    88
8      dog    97

dend2 <- color_labels(dend, k=8, groupLabels = scores )     # Add colors to labels 

(here I would like to have the gradient of colours depending on score) This plot was generated with other tool but it is what I expect to generate with some gradients color tool in R

Community
  • 1
  • 1
carolet
  • 1
  • 1
  • 3
    provide a reproducible example -for help see [this link](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) also show us what you've tried thus far... – Cyrus Mohammadian Aug 18 '16 at 18:49
  • 1
    Construct and post a data example with a smaller number of items. (MWE) – IRTFM Aug 18 '16 at 18:49
  • [this](http://stackoverflow.com/questions/13850896/hierarchical-cluster-labeling-with-plots/13852099#13852099) should help. – agstudy Aug 18 '16 at 19:35
  • what is ``read.tree("species_tree.ph")`` ? same with ``scores``. please provide actual data! this is not a reproducible example. Take the time to read the literature we provided you. – Cyrus Mohammadian Aug 18 '16 at 20:07
  • Hi Cyrus, thanks for answering. I posted the species_tree.ph (tree) content and the scores.csv (scores table) in the example, so you can use the same data. – carolet Aug 18 '16 at 20:13
  • you could try the [dendextend package](https://cran.r-project.org/web/packages/dendextend/vignettes/Cluster_Analysis.html). – desc Aug 18 '16 at 22:08

0 Answers0