【问题标题】:Can't Plot Dendrogram (invalid dendrogram input error)无法绘制树状图(无效的树状图输入错误)
【发布时间】:2020-02-07 10:18:24
【问题描述】:

我的数据集中有 583 个观察值,我需要使用其中的 100 个来制作树状图。但是我在 plot() 函数步骤中收到以下错误。

如何解决/解决这个问题?

##For 100 Observations
set.seed(44)
idx_100 <- sample(1:nrow(ilpd_df), 100)
distance_matrix_100 <- dist(as.matrix(ilpd_df[idx_100,-c(1,2,10,11)]), 
                        method = "euclidean") #Creates Hierarchical Clustering Solution

hc_100 <- hclust(distance_matrix_100)
plot(hc_100, hang = -1, labels=ilpd_df$Class) #CANT PLOT DUE TO INVALID INPUT ERROR

【问题讨论】:

    标签: r cluster-analysis hierarchical-clustering dendrogram


    【解决方案1】:

    你确定你使用正确的参数来绘制你的树状图。因此,我在这里分享 S3 方法,用于在树状图上使用绘图功能。 “挂起”不包含在此列表中。

    树状图的S3方法

      plot(x, type = c("rectangle", "triangle"),
      center = FALSE,
      edge.root = is.leaf(x) || !is.null(attr(x,"edgetext")),
      nodePar = NULL, edgePar = list(),
      leaflab = c("perpendicular", "textlike", "none"),
      dLeaf = NULL, xlab = "", ylab = "", xaxt = "n", yaxt = "s",
      horiz = FALSE, frame.plot = FALSE, xlim, ylim, …)
    

    【讨论】:

      【解决方案2】:

      您能否提供一些可用于复制问题的最少数据?

      我发现plot.hclust() 没有问题 (R 3.6.1)。

      以下简单代码

      hc <- hclust(dist(USArrests)^2, "cen")
      class(hc)  # [1] "hclust"
      plot(hc, hang = -1, main = "Sample Tree", cex = .5)
      

      生产

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-06
        • 2015-05-21
        • 1970-01-01
        • 2022-01-19
        • 1970-01-01
        • 2021-06-07
        • 2020-05-07
        • 1970-01-01
        相关资源
        最近更新 更多