我想给我的树标签添加不同的颜色。因此,我想到了将树与元数据框架相结合,它似乎工作得很好。唯一的问题是我不知道如何指定颜色。目前,它们是随机选择的。如果可能的话,我更喜欢以矢量的形式读取颜色
library("ggplot2")
library("ggtree")
tree <- rtree(20)
meta <- data.frame("id" = c("t4", "t6", "t17", "t13", "t12", "t8", "t16", "t10", "t20", "t2", "t14", "t18", "t11", "t7", "t15", "t9", "t19", "t3", "t1", "t5"),
"num" = c(rep("1", 5), rep("2", 4), rep("3", 6), rep("4", 5)),
"col" = c(rep("orange", 5), rep("gold1", 4), rep("steelblue1", 6), rep("magenta1", 5)))
p <- ggtree(tree)
p %<+% meta +
geom_tiplab(aes(color=num))+
geom_tippoint(aes(color=num))+
theme(legend.position = "none")
现在,对于我的目的来说,这看起来很好,只是颜色与col向量中的颜色不匹配。我试着把颜色加进去
ggtree(tree, aes(color=col))
,但这并不奏效。
我试过了
this
并在元数据中用列直接说明颜色
p %<+% meta +
geom_tiplab(aes(color=col))+
geom_tippoint(aes(color=col))+
theme(legend.position = "none")
我尝试添加scale_fill_manual,但再次没有成功
p %<+% meta +
geom_tiplab(aes(color=num))+
geom_tippoint(aes(color=num))+
theme(legend.position = "none")+
scale_fill_manual(values=c("1"="orange", "2"="gold1", "3"="steelblue1", "4"="magenta1"))