我正在 R 上用 ggtree 构建一棵树。
library(ggtree)
这是newick文件内容:
tree = read.newick("newick_tree")
这是我使用的代码:
colfunc <- colorRampPalette(c("red", "blue"))
col=colfunc(110)
for (i in 1:length(tree$node.label)){
if(as.vector(tree$node.label[i])>0.99){
col[i]<-'#CB1414'
} else if(as.vector(tree$node.label[i])>0.90 & (as.vector(tree$node.label[i]) < 0.99)){
col[i]<-'#F0F014'
} else if(as.vector(tree$node.label[i])>0.76 & (as.vector(tree$node.label[i]) < 0.90)){
col[i]<-'#098527'
} else if(as.vector(tree$node.label[i])>0.51 & (as.vector(tree$node.label[i]) < 0.76)){
col[i]<-'#18D8F7'
} else if(as.vector(tree$node.label[i])>0 & (as.vector(tree$node.label[i]) < 0.50)){
col[i]<-'#1B72DB'
}
}
p<-ggtree(tree,size=0.5,branch.length="none") +geom_tiplab(size = 2, col ="black") + geom_nodepoint(color=col, alpha=1, size=1.5, show.legend = TRUE)+
geom_treescale(x=30, y=1)
为了根据引导级别获得点颜色,我使用了这部分:变量geom_nodepoint(color=col, alpha=1, size=1.5, show.legend = TRUE)
在哪里,col
例如:
> col
[1] "#CB1414" "#FC0002" "#FA0004" "#F70007" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414"
[15] "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#F0F014" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414"
[29] "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414"
[43] "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#F0F014" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#098527" "#CB1414"
[57] "#CB1414" "#18D8F7" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414"
[71] "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#F0F014" "#098527" "#098527" "#CB1414"
[85] "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#F0F014" "#CB1414" "#098527" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#1B72DB"
[99] "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414" "#CB1414"
我根据此变量中的数字制作:
> tree$node.labe
[1] "1" "" "" "0.99" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
[21] "1" "0.97" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
[41] "1" "1" "1" "1" "1" "1" "1" "1" "1" "0.98" "1" "1" "1" "1" "0.89" "1" "1" "0.64" "1" "1"
[61] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
[81] "0.92" "0.8" "0.77" "1" "1" "1" "1" "1" "0.96" "1" "0.84" "1" "1" "1" "1" "1" "1" "0.48" "1" "1"
[101] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
但该选项 show.legend = TRUE
不适用于此。有人有想法吗?我也尝试添加p + theme(legend.position="right")
,但仍然没有传说。
谢谢您的帮助。
这是代理(树)