基于帖子ggdendrogram labels,我尝试将dict减速度更改为dict <名称(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)