首页 > 解决方案 > ggdendrogram 标签 - 自动设置名称

问题描述

基于帖子ggdendrogram 标签,我尝试将 dict 减速更改为 dict <- names(treeList)。这没用。为什么?可以修复吗?

代码:

library(IncDTW)
library(ggplot2)
library(ggdendro) 

A <- matrix(1:50, nrow = 50, ncol = 1)
B <- matrix(1:100, nrow = 75, ncol = 1)
C <- matrix(25:49, nrow = 25, ncol = 1)
D <- matrix(1:50, nrow = 50, ncol = 1)
treeList <- list(A,B,C,D)

names(treeList)[1] <- "A"
names(treeList)[2] <- "B"
names(treeList)[3] <- "C"
names(treeList)[4] <- "D"

result <- dtw_dismat(treeList, dist_method = "norm2", return_matrix = F)
distMatrixResult <- result$dismat
hc <- hclust(distMatrixResult, method = "average")
hc <- dendro_data(hc)
dict <- names(treeList)
hc$labels$label <- sapply(hc$labels$label, function(x) dict[[as.character(x)]])
ggdendrogram(hc)

标签: r

解决方案


推荐阅读