Apply ifelse function to colour tips of phylogenetic fan

泄露秘密 提交于 2019-12-02 04:38:51

Your code works correctly, but the colors are not ordered according to the order of tip labels (check phyloFan$tip.label). Reordering the colors with the match function will solve the color assignment.

require(ape)

# generate a random tree, because importing yours does not work for me
# skip this step in your code
set.seed(12345)
phyloFan <- rtree(n = nrow(LU), tip.label = row.names(LU))

# create color vector ordered according to the tip labels
cols <- ifelse(LU != "O", "blue", "darkgreen")[match(phyloFan$tip.label, row.names(LU))]

# plot with ordered colors
plot(phyloFan, type = "fan", tip.color = cols, label.offset = 0.1)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!