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)
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