gpt4 book ai didi

r - 圆形系统发育树上的节点标签

转载 作者:行者123 更新时间:2023-12-04 11:59:15 24 4
gpt4 key购买 nike

我正在尝试创建圆形系统发育树。我有这部分代码:

fit<- hclust(dist(Data[,-4]), method = "complete", members = NULL)

nclus= 3
color=c('red','blue','green')
color_list=rep(color,nclus/length(color))
clus=cutree(fit,nclus)

plot(as.phylo(fit),type='fan',tip.color=color_list[clus],label.offset=0.2,no.margin=TRUE, cex=0.70, show.node.label = TRUE)

这是结果:
enter image description here

此外,我试图为每个节点显示标签并为分支着色。任何建议如何做到这一点?

谢谢!

最佳答案

当你说“颜色分支”时,我假设你的意思是给边缘上色。这似乎有效,但我必须认为有更好的方法。

使用内置 mtcars数据集在这里,因为您没有提供您的数据。

plot.fan <- function(hc, nclus=3) {
palette <- c('red','blue','green','orange','black')[1:nclus]
clus <-cutree(hc,nclus)
X <- as.phylo(hc)
edge.clus <- sapply(1:nclus,function(i)max(which(X$edge[,2] %in% which(clus==i))))
order <- order(edge.clus)
edge.clus <- c(min(edge.clus),diff(sort(edge.clus)))
edge.clus <- rep(order,edge.clus)
plot(X,type='fan',
tip.color=palette[clus],edge.color=palette[edge.clus],
label.offset=0.2,no.margin=TRUE, cex=0.70)
}
fit <- hclust(dist(mtcars[,c("mpg","hp","wt","disp")]))
plot.fan(fit,3); plot.fan(fit,5)





关于“标记节点”,如果您的意思是标记提示,则看起来您已经这样做了。如果你想要不同的标签,不幸的是,不像 plot.hclust(...) labels=...论据被驳回。您可以尝试使用 tiplabels(....)功能,但它似乎不太适合 type="fan" .标签来自 Data 的行名,因此您最好的 IMO 选择是在聚类之前更改行名称。

如果您实际上是指标记节点(边缘之间的连接点,请查看 nodelabels(...) 。我没有提供工作示例,因为我无法想象您会在那里放置什么标签。

关于r - 圆形系统发育树上的节点标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27475106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com