R中漂亮的树状图?

时间:2014-01-28 15:54:19

标签: r cluster-analysis dendrogram traminer

我的树形图非常丑陋,处于难以理解的边缘,通常看起来像这样:

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?

中完成此任务

1 个答案:

答案 0 :(得分:9)

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

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