如何使用ggplot绘制T-SNE聚类 [英] How to use ggplot to plot T-SNE clustering
本文介绍了如何使用ggplot绘制T-SNE聚类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是使用IRIS数据的t-SNE代码:
Here is the t-SNE code using IRIS data:
library(Rtsne)
iris_unique <- unique(iris) # Remove duplicates
iris_matrix <- as.matrix(iris_unique[,1:4])
set.seed(42) # Set a seed if you want reproducible results
tsne_out <- Rtsne(iris_matrix) # Run TSNE
# Show the objects in the 2D tsne representation
plot(tsne_out$Y,col=iris_unique$Species)
产生以下情节的地方:
我如何使用GGPLOT来绘制图形?
How can I use GGPLOT to make that figure?
推荐答案
我认为最简单/最干净的 ggplot
方式是将所需的所有信息存储在 data.frame中
然后将其绘制。从上面粘贴的代码开始,这应该可以工作:
I think the easiest/cleanest ggplot
way would be to store all the info you need in a data.frame
and then plot it. From your code pasted above, this should work:
library(ggplot2)
tsne_plot <- data.frame(x = tsne_out$Y[,1], y = tsne_out$Y[,2], col = iris_unique$Species)
ggplot(tsne_plot) + geom_point(aes(x=x, y=y, color=col))
我使用常规 plot
函数绘制的图是:
My plot using the regular plot
function is:
plot(tsne_out$Y,col=iris_unique$Species)
这篇关于如何使用ggplot绘制T-SNE聚类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文