以文本/表格格式显示TraMineR(R)树状图
我使用以下R代码生成一个树状图(见附图),带有基于TraMineR序列的标签:以文本/表格格式显示TraMineR(R)树状图,r,cluster-analysis,dendrogram,traminer,R,Cluster Analysis,Dendrogram,Traminer,我使用以下R代码生成一个树状图(见附图),带有基于TraMineR序列的标签: library(TraMineR) library(cluster) clusterward <- agnes(twitter.om, diss = TRUE, method = "ward") plot(clusterward, which.plots = 2, labels=colnames(twitter_sequences)) 库(TraMineR) 图书馆(群集) 群集问题涉及群集包。由agnes返
library(TraMineR)
library(cluster)
clusterward <- agnes(twitter.om, diss = TRUE, method = "ward")
plot(clusterward, which.plots = 2, labels=colnames(twitter_sequences))
库(TraMineR)
图书馆(群集)
群集问题涉及群集
包。由agnes
返回的agnes.object
的帮助页面
(请参阅)说明此对象包含一个类似于order
的order.lab
组件,但包含观察标签而不是观察编号。此组件仅在标记原始观察时可用。”
TraMineR生成的相异性矩阵(twitter.om
,在您的例子中)当前没有将序列标签保留为行名和列名。要获取order.lab
组件,您必须手动将序列标签分配为twitter.om
矩阵的rownames
和colnames
。我在这里用TraMineR包提供的mvad
数据进行说明
library(TraMineR)
data(mvad)
## attaching row labels
rownames(mvad) <- paste("seq",rownames(mvad),sep="")
mvad.seq <- seqdef(mvad[17:86])
## computing the dissimilarity matrix
dist.om <- seqdist(mvad.seq, method = "OM", indel = 1, sm = "TRATE")
## assigning row and column labels
rownames(dist.om) <- rownames(mvad)
colnames(dist.om) <- rownames(mvad)
dist.om[1:6,1:6]
## Hierarchical cluster with agnes library(cluster)
cward <- agnes(dist.om, diss = TRUE, method = "ward")
## here we can see that cward has an order.lab component
attributes(cward)
希望这有帮助。非常感谢!这很有帮助!
## plot the dendrogram
plot(cward, which.plot = 2, labels=FALSE)
## and select the groups manually from the plot
x <- identify(as.hclust(cward)) ## Terminate with second mouse button
## number of groups selected
length(x)
## list of members of the first group
x[[1]]