2011-08-29 101 views

回答

3

可以做,使用cutree():

hc <- hclust(dist(USArrests), "ave") 
plot(hc) 
rect.hclust(hc, h = 50) 
cutree(hc, h = 50) 
+0

我正在此错误” 错误在矩形(M [其中[N]] + 0.66,par(“usr”)[3L],m [which [n] + 1] + 0.33,: 当我使用rect.hclust时,尚未调用plot.new。如何解决此错误。 – akash

+0

您需要首先绘制树状图,然后绘制树状图n使用rect。 – EDi

0

我解决了 “错误在矩形(M [其中[N]] + 0.66,参数(” USR“)[3L],M [其中[N] + 1] + 0.33,:plot.new没有被调用尚未 “绘制树形图如下:

USA.tree <- hclust(dist(USAarrest) 
plot(hclust(dist(USAarrest))) #if I use plot(USA.tree) returns an error 
x <- rect.hclust(USA.tree, k=3, border="red") 
# x <- rect.hclust(USA.tree, h = 50, which = c(2,7), border = 3:4) 
x