HDBSCAN Visualization in R to apply text labels instead of numbers

I am trying to run HDBSCAN algortihm in R via largeVis package. For visualization of clusters. I am using gplot function in largeVis. Is it possible to change the labels of my data points in the plot from integers to string? I am using Iris dataset with little modification in "class" column and using "class" column as row headers. Is it possible to visualize my current row headers in the plot instead of node numbers?

x1 <- iris[,-5]
row.names(x1) <- paste0("Iris-", iris[,5], " ", 1:nrow(x1))
View(x1)

Iris_modified行标题

vis <- largeVis::largeVis(x1)
clustering <- largeVis::hdbscan(vis)
largeVis::gplot(clustering,t(vis$coords), text = TRUE)

在这里输入图像描述


The function itself doesn't have an easy option to plot the rownames, bit it does return a ggplot object and you can add additional layers to that. Here's how you can plot with the rownames

library(ggplot2)
pp <- largeVis::gplot(clustering,t(vis$coords), text = FALSE) + 
  geom_label(aes(label=rownames(x1)[label+1]), size=2.5, label.size=0.1, alpha=0.7)

Internally it builds a data.frame and indexes each node start at (for some very non R-like reason) 0. We can use that index to look up the rowname for that observations and use that as a label. Here I kept most of the styling used by the default options in the base functions.

在这里输入图像描述

链接地址: http://www.djcxy.com/p/30962.html

上一篇: 如何使用ggplot2将新的图例添加到复杂的散点图

下一篇: R中的HDBSCAN可视化应用文本标签而不是数字