如何使用同一数据框中另一列的分类变量在 R 中的 hclust 中标记树状图的叶子
我想更改树状图叶子的默认标签,以匹配使用 dplyr
group_by
和 summarise
生成的数据框中的分类变量列功能。这是数据框的屏幕截图。 我想使用“m”列变量作为树状图的标签。
这是生成树状图的代码(sfdf_lop
是数据帧)
csfdf_lop <- hclust(dist(sfdf_lop[, -1]), method = "complete")
plot(csfdf_lop)
如何使用“m”列中的变量来标记叶子,而不是默认编号的叶子?
编辑下面是使用建议代码
tempdf<- as.data.frame(sfdf_lop)
row.names(tempdf)<- tempdf$m
csfdf_lop <- hclust(dist(tempdf[, -1]), method = "complete")
plot(csfdf_lop)
I would like to change the default labels for the leaves of a dendrogram to match a categorical variable column in a dataframe generated using dplyr
group_by
and summarise
functions. This is a screenshot of the dataframe.
I would like to use the 'm' column variables as the labels for the dendrogram.
This is the code to generate the dendrogram (sfdf_lop
is the dataframe)
csfdf_lop <- hclust(dist(sfdf_lop[, -1]), method = "complete")
plot(csfdf_lop)
and the output looks like this:
How do I use the variables in the column 'm' to label the leaves, in place of the default numbered leaves?
Edit Below is the result of using the suggested code
tempdf<- as.data.frame(sfdf_lop)
row.names(tempdf)<- tempdf$m
csfdf_lop <- hclust(dist(tempdf[, -1]), method = "complete")
plot(csfdf_lop)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将数据转换为 data.frame 并将 row.names 定义为等于 M 列。
If you convert your data to data.frame and define the row.names to equal column M.