本文介绍了在带有ggdendro的树状图片段下显示可变标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的问题与Andrie对我早期问题的答案有关。我的问题是,是否可以在树状图的相应部分下显示变量标签和汽车标签? library(ggplot2) library(ggdendro) data(mtcars)x< - as.matrix(scale(mtcars)) dd.row< - as.dendrogram(hclust(dist(t(x)))) ddata_x< - dendro_data(dd.row) p2 geom_segment(aes(x = x0,y = y0,xend = x1,yend = y1)) print(p2) 解决方案请确保您拥有 ggdendro 然后使用便利函数 ggdendrogram : library(ggplot2) library(ggdendro) ggdendrogram(dd.row) 如果你想要满控制标签的显示方式,您可以使用以下任一方式从 ddata_x 中提取和操作这些标签: ddata_x $ labels label(ddata_x) p2 + geom_text(data = label(ddata_x),aes(label = text,x = x,y = 0)) 您可以在小插曲 vignette ggdendro) My question is related to Andrie's answer to my earlier question. My question is whether is this possible to display the variable labels and car label under the corresponding segments of the dendrogram? library(ggplot2)library(ggdendro)data(mtcars)x <- as.matrix(scale(mtcars))dd.row <- as.dendrogram(hclust(dist(t(x))))ddata_x <- dendro_data(dd.row)p2 <- ggplot(segment(ddata_x)) +geom_segment(aes(x=x0, y=y0, xend=x1, yend=y1))print(p2) 解决方案 Make sure you have version 0.0-7 of ggdendro and then use the convenience function ggdendrogram:library(ggplot2)library(ggdendro)ggdendrogram(dd.row)If you want full control over how the labels are displayed, you can extract and manipulate these from ddata_x using either:ddata_x$labelslabel(ddata_x)To add to your plot:p2 + geom_text(data=label(ddata_x), aes(label=text, x=x, y=0))You can find more information in the vignette, vignette("ggdendro") 这篇关于在带有ggdendro的树状图片段下显示可变标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 14:40