gpt4 book ai didi

r - R 中漂亮的树状图?

转载 作者:行者123 更新时间:2023-12-04 17:35:25 26 4
gpt4 key购买 nike

我的树状图非常丑陋,几乎无法阅读,通常看起来像这样:

enter image description here

library(TraMineR)
library(cluster)
data(biofam)
lab <- c("P","L","M","LM","C","LC","LMC","D")
biofam.seq <- seqdef(biofam[1:500,10:25], states=lab)

ccost <- seqsubm(biofam.seq, method = "CONSTANT", cval = 2, with.missing=TRUE)
sequences.OM <- seqdist(biofam.seq, method = "OM", norm= TRUE, sm = ccost,
with.missing=TRUE)

clusterward <- agnes(sequences.OM, diss = TRUE, method = "ward")
plot(clusterward, which.plots = 2)

我想要创建的是类似于以下内容的内容,这意味着一个圆形的树状图,其中可以仔细控制标签的大小,以便它们实际上是可见的:

enter image description here

我怎样才能在 R 中做到这一点?

最佳答案

以下解决方案可能不是最佳的,但值得一试:

library(ape)
CL1 <- as.hclust(clusterward)
CL2 <- as.phylo(CL1)
plot(CL2, type="fan", cex=0.5)

enter image description here

主要问题显然是仍然有太多对象,因此标签太多。要关闭标签,请使用参数 show.tip.label=FALSE .您也可以使用 no.margin=TRUE 去掉边距以占用整个设备。 :
plot(CL2, type="fan", show.tip.label=FALSE, no.margin=TRUE)

enter image description here

关于r - R 中漂亮的树状图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21410441/

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