R 切割树状图

R 切割树状图,r,list,dendrogram,ape,R,List,Dendrogram,Ape,我有一个树状图: 最后是这个树状图: 我得到的最接近的结果是使用ape的drop.tip,但问题是如果我的depth.cutoff包含所有叶子,如本例中所示,它将返回NULL 也许有人知道,如果元素的深度低于depth.cutoff,是否以及如何从表示树状图的嵌套列表中删除元素 或者,也许我可以将树状图转换为data.frame,其中还列出了每个节点的深度,包括深度为0的叶子,删除所有深度的行cut将在指定高度切割树。它将返回上下部分的列表 获取图片的一种可能更直接的方法是设置要绘制的限制 pl

我有一个树状图:

最后是这个树状图:

我得到的最接近的结果是使用ape的drop.tip,但问题是如果我的depth.cutoff包含所有叶子,如本例中所示,它将返回NULL

也许有人知道,如果元素的深度低于depth.cutoff,是否以及如何从表示树状图的嵌套列表中删除元素

或者,也许我可以将树状图转换为data.frame,其中还列出了每个节点的深度,包括深度为0的叶子,删除所有深度的行cut将在指定高度切割树。它将返回上下部分的列表


获取图片的一种可能更直接的方法是设置要绘制的限制

plot(dend, horiz = TRUE, xlim=c(6,4.75))

当然,如果OP想要做的只是绘制一个特定的部分,那么这是一种更“方便”的方式。非常感谢@SymbolXau。你知道有没有办法让所有的分支都在同一条线上结束?不是在绘图中而是在dend对象中?
depth.cutoff <- 4.75
plot(dend,horiz = TRUE)
abline(v=depth.cutoff,col="red",lty=2)
cut(dend, h = depth.cutoff)$upper

# $upper
# 'dendrogram' with 2 branches and 5 members total, at height 5.887262 
# 
# $lower
# $lower[[1]]
# 'dendrogram' with 2 branches and 6 members total, at height 4.515119 
# 
# $lower[[2]]
# 'dendrogram' with 2 branches and 2 members total, at height 3.789259 
# 
# $lower[[3]]
# 'dendrogram' with 2 branches and 5 members total, at height 3.837733 
# 
# $lower[[4]]
# 'dendrogram' with 2 branches and 3 members total, at height 3.845031 
# 
# $lower[[5]]
# 'dendrogram' with 2 branches and 4 members total, at height 4.298743


plot(cut(dend, h = depth.cutoff)$upper, horiz = T)
plot(dend, horiz = TRUE, xlim=c(6,4.75))