【问题标题】:The leaf's labels aren't showing completely when I use as.dendrogram当我使用 as.dendrogram 时,叶子的标签没有完全显示
【发布时间】:2019-04-03 14:49:58
【问题描述】:

当我使用“as.dendrogram”绘制树状图时,所有的叶子标签都被剪掉了。 请参阅下面的链接图像作为示例:

当我使用“hclust”绘图时(所有标签都正确显示) Dendrogram 1

当我使用“as.dendrogram”绘图时 Dendrogram 2

代码:

我创建的数据只是为了说明问题

test <- matrix(c(34,34,32,27,12,1,2,1,1,1), ncol=2)
colnames(test) <- c('Variable1', 'Variable2')
rownames(test) <- c('African Forest Elephant', 'Asian Domestic Elephant','African White Rhino','West African Giraffe','African Mountain Gorilla')
test_table <- as.table(test)

绘制第一个链接图像

hctest = hclust(dist(test_table))
plot(hctest, axes = FALSE)

第二个

hctest = as.dendrogram(hctest)
plot(hctest, edge.root = TRUE, horiz = TRUE)

PS:如果我使用“horiz = FALSE”,同样的问题仍然存在。我尝试导出图像并尝试使用 R markdown,但没有任何变化。

【问题讨论】:

    标签: r label axis-labels hierarchical-clustering hclust


    【解决方案1】:

    您可以使用par 通过调整绘图边距mar=c(bottom, left, top, right) 来解决此问题。 (默认为c(5, 4, 4, 2) + 0.1)。

    par(mar=c(5, 4, 4, 10) + 0.1)
    plot(hctest, edge.root=TRUE, horiz=TRUE)
    

    数据

    hctest <- structure(list(structure(5L, members = 1L, height = 0, label = "African Mountain Gorilla", leaf = TRUE), 
        structure(list(structure(4L, members = 1L, height = 0, label = "West African Giraffe", leaf = TRUE), 
            structure(list(structure(3L, members = 1L, height = 0, label = "African White Rhino", leaf = TRUE), 
                structure(list(structure(1L, label = "African Forest Elephant", members = 1L, height = 0, leaf = TRUE), 
                    structure(2L, label = "Asian Domestic Elephant", members = 1L, height = 0, leaf = TRUE)), members = 2L, midpoint = 0.5, height = 1)), members = 3L, midpoint = 0.75, height = 2.23606797749979)), members = 4L, midpoint = 0.875, height = 7.07106781186548)), members = 5L, midpoint = 0.9375, height = 22.0227155455452, class = "dendrogram")
    

    【讨论】:

      猜你喜欢
      • 2019-03-12
      • 1970-01-01
      • 2019-12-24
      • 2015-08-05
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      • 2011-10-08
      相关资源
      最近更新 更多