gpt4 book ai didi

r - 如何使用 ggplot 绘制 T-SNE 聚类

转载 作者:行者123 更新时间:2023-12-02 06:29:12 33 4
gpt4 key购买 nike

这是使用 IRIS 数据的 t-SNE 代码:

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)

这产生了这个情节:

enter image description here

我怎样才能使用 GGPLOT 来制作那个数字?

最佳答案

我认为最简单/最干净 ggplot方法是将您需要的所有信息存储在 data.frame 中然后绘制它。从上面粘贴的代码中,这应该有效:

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

enter image description here

我的情节使用常规 plot功能是:
plot(tsne_out$Y,col=iris_unique$Species)

enter image description here

关于r - 如何使用 ggplot 绘制 T-SNE 聚类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44837536/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com