Dendrogram图删除分支末端的树标签

问题描述 投票:0回答:1

使用位于此处的示例https://www.datacamp.com/community/tutorials/hierarchical-clustering-R和位于https://archive.ics.uci.edu/ml/datasets/seeds#的数据,我试图在使用color_branches时删除树状图底部的标签

plot(hclust_avg, labels=FALSE)起作用时,但使用color_branches以后不起作用。有没有办法删除它们?

`set.seed(786)
seeds_df <- read.csv("seeds_dataset.txt",sep = '\t',header = FALSE)
feature_name <- c('area','perimeter','compactness','length.of.kernel','width.of.kernal','asymmetry.coefficient','length.of.kernel.groove','type.of.seed')
colnames(seeds_df) <- feature_name
seeds_df<- seeds_df[complete.cases(seeds_df), ]
seeds_label <- seeds_df$type.of.seed
seeds_df$type.of.seed <- NULL
seeds_df_sc <- as.data.frame(scale(seeds_df))
dist_mat <- dist(seeds_df_sc, method = 'euclidean')
hclust_avg <- hclust(dist_mat, method = 'average')
cut_avg <- cutree(hclust_avg, k = 3)
suppressPackageStartupMessages(library(dendextend))
avg_dend_obj <- as.dendrogram(hclust_avg)
avg_col_dend <- color_branches(avg_dend_obj, h = 3)
plot(avg_col_dend)`
plot label dendrogram dendextend
1个回答
0
投票

通过将标签白色标记为背景来解决这个问题

avg_dend_obj <- as.dendrogram(hclust_avg) labels_colors(avg_dend_obj) <- "white" plot(avg_dend_obj)enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.