无法让 ggraph 显示树状图的标签
Can't get ggraph to display labels for a dendrogram
我使用 ggraph 可视化聚类分析的结果。但我无法让 ggraph 显示标签。我尝试将它们作为行名添加到数据中,并尝试将它们作为向量添加到标签中——但都无济于事。我对 ggraph
很陌生:欢迎任何帮助或批评。
MWE:
library(tidyverse)
library(cluster)
library(ggraph)
mat <- matrix(rnorm(n = 25, mean = 6, sd = 2.7))
rownames(mat) <- sample(LETTERS, size = 25, replace = FALSE)
dend_labels <- rownames(mat)
mat %>%
dist(method = "euclidean") %>%
agnes(metric = "ward") %>%
as.hclust() %>%
as.phylo() %>%
ggraph(layout = "dendrogram") +
geom_edge_elbow() +
geom_node_label(aes(label = dend_labels))
你在找这个吗?
mat %>%
dist(method = "euclidean") %>%
agnes(metric = "ward") %>%
as.hclust() %>%
as.phylo() %>%
ggraph(layout = "dendrogram") +
geom_edge_elbow() +
geom_node_label(aes(label = name, filter = leaf)) +
theme_graph()
我使用 ggraph 可视化聚类分析的结果。但我无法让 ggraph 显示标签。我尝试将它们作为行名添加到数据中,并尝试将它们作为向量添加到标签中——但都无济于事。我对 ggraph
很陌生:欢迎任何帮助或批评。
MWE:
library(tidyverse)
library(cluster)
library(ggraph)
mat <- matrix(rnorm(n = 25, mean = 6, sd = 2.7))
rownames(mat) <- sample(LETTERS, size = 25, replace = FALSE)
dend_labels <- rownames(mat)
mat %>%
dist(method = "euclidean") %>%
agnes(metric = "ward") %>%
as.hclust() %>%
as.phylo() %>%
ggraph(layout = "dendrogram") +
geom_edge_elbow() +
geom_node_label(aes(label = dend_labels))
你在找这个吗?
mat %>%
dist(method = "euclidean") %>%
agnes(metric = "ward") %>%
as.hclust() %>%
as.phylo() %>%
ggraph(layout = "dendrogram") +
geom_edge_elbow() +
geom_node_label(aes(label = name, filter = leaf)) +
theme_graph()