2016-11-22 79 views
0

我使用HOPACH聚類 - 是否有一種方法可視化只有最大的n簇(例如,只繪製3個最大)?當前代碼可視化所有羣集。聚類 - 繪製最大的n個簇

library(cluster) 
library(hopach) 

distance =distancematrix(DNA[1:30],"cosangle") 
hobpach.DNA =hopach(DNA[1:30],dmat=distance) 

labels = c(hobpach.DNA$clustering$labels) 

table(labels, DNA$class) 

#Plots all clusters 

clusplot(DNA[1:30], hobpach.DNA$clustering$labels, main='Cluster Vis', 
    color=TRUE, shade=TRUE, 
    labels=2, lines=0) 

回答

0

直接在clusplot沒有這樣的東西。但是,您可以輕鬆找出哪些集羣最大,然後僅將這些集羣提供給clusplot函數。

# find the indicees of the largest clusters 
biggest_indicees <- labels %in% names(sort(table(labels), decreasing = TRUE)[1:3]) 

# plot three largest clusters 
clusplot(df[biggest_indicees, ], labels[biggest_indicees], main = 'Cluster Vis', 
     color = TRUE, shade = TRUE, labels = 2, lines = 0) 
+0

我有在DF一個輕微的問題...錯誤[biggest_indicees,]:輸入「關閉」的 對象不subsettable –

+0

你,你在上面的代碼中提到定義標籤?你有'labels = c(hobpach.DNA $ clustering $ labels)'。 – shadow

+0

是的,我正在網上搜索這個問題,但沒有運氣。 –