有没有办法从hclust获得"子树"?(R)

Tal*_*ili 4 r cluster-analysis

我希望从一个hclust对象创建一个"子树".

例如,假设我有以下对象:

a <- list()  # initialize empty object
a$merge <- matrix(c(-1, -2,
                    -3, -4,
                     1,  2,
             -5,-6,
             3,4), nc=2, byrow=TRUE ) 
a$height <- c(1, 1.5, 3,4,4.5)    # define merge heights
a$order <- 1:6              # order of leaves(trivial if hand-entered)
a$labels <- 1:6# LETTERS[1:4]    # labels of leaves
class(a) <- "hclust"        # make it an hclust object
plot(a)                     # look at the result   
Run Code Online (Sandbox Code Playgroud)

现在我希望从中提取以下子树:

a <- list()  # initialize empty object
a$merge <- matrix(c(-1, -2,
                    -3, -4,
                     1,  2
                ), nc=2, byrow=TRUE ) 
a$height <- c(1, 1.5, 3)    # define merge heights
a$order <- 1:4             # order of leaves(trivial if hand-entered)
a$labels <- 1:4# LETTERS[1:4]    # labels of leaves
class(a) <- "hclust"        # make it an hclust object
plot(a)                     # look at the result   
Run Code Online (Sandbox Code Playgroud)

我怎么能访问它?

(我知道cutree可以让我得到子树的对象,但不能创建一个真正的hclust对象)

谢谢你的帮助,

塔尔

nic*_*ico 6

不确定这是你在找什么,但你可以

a <- as.dendrogram(a)
branch1 <- a[[1]]
branch2 <- a[[2]]

par(mfrow=c(1,3))
plot(a)
plot(branch1)
plot(branch2)
Run Code Online (Sandbox Code Playgroud)