我有一个由R导入的150个基因的树状图,我的数据框中有相同的树形图标记,得分值从0到200,与树形图无关。
我想使用从蓝色到红色的渐变颜色,使用表中的得分值为树形图的标签着色。我在以下链接中找到了类似问题的答案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)
但我无法弄清楚如何为我的代码转换示例代码,因为:
1)它们都没有与树形图匹配,外部值由标签和
连接
2)我想根据分数而不是随机颜色分配颜色。
以下是我的代码
的数据示例library(ape)
library(dendextend)
# Load tree
MyTree <- read.tree("species_tree.ph")
<(>(浣熊:19.19959,熊: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,狗: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
(这里我希望颜色的渐变取决于分数) This plot was generated with other tool but it is what I expect to generate with some gradients color tool in R