【问题标题】:Plot horizontal dendrogram with hanging leaves? (R)用挂叶绘制水平树状图? (右)
【发布时间】:2013-06-09 21:38:21
【问题描述】:

我想创建一个带有水平标签的树状图,但是让叶子根据它们的高度悬挂,而不是仅仅下降到图的边缘。

例子:

par(mfrow = c(1,2))
hc <- hclust(dist(USArrests), "ave")
plot(hc) # a plot with hanging branches
plot(as.dendrogram(hc), horiz = TRUE) # a horizontal plot, but the branches are not hanging

关于如何编程有什么建议吗?

谢谢。

【问题讨论】:

  • 我认为您可以使用?dendrogram 中的最后一个示例做一些接近此的事情。
  • 嗨,费迪南德,我承认我不知道怎么做。你能扩展你的想法吗?
  • 使用edgetext 属性,使用dendrapply 为每条边设置。这只是一个想法,我现在没有时间去追求这个。 :-(
  • Have you seen this?它遍历 latticeggplot2 中的树状图。

标签: r dendrogram hclust dendextend


【解决方案1】:

为了记录,我已经实现了一个hang.dendrogram 函数(在dendextend 包中),以允许在创建树状图之后(不仅在从hclust 更改为树状图期间)。使用方法如下:

install.packages("dendextend")
library(dendextend)

dend <- as.dendrogram(hclust(dist(USArrests), "ave"))
par(mar = c(5,5,5,5))
plot(hang.dendrogram(dend), horiz = TRUE)

【讨论】:

    【解决方案2】:

    您可以在as.dendrogram 函数中更改hang 的值。

    par(mfrow = c(1,2))
    hc <- hclust(dist(USArrests), "ave")
    plot(hc)
    plot(as.dendrogram(hc, hang=0.02), horiz = TRUE)
    

    【讨论】:

      猜你喜欢
      • 2020-07-03
      • 2020-11-27
      • 1970-01-01
      • 2015-05-21
      • 2015-09-05
      • 2019-05-29
      • 2015-12-15
      • 2013-06-18
      • 2011-06-10
      相关资源
      最近更新 更多