0

I did a tSNE with the function Rtsne. Now I want to visualize it. I have predefined groups. Like the Species in iris. I want to color the points by this groups. This does not help me Coloring the points by category in R. So far, i did this

iris <- unique(iris)
iris_num <- iris[ ,1:4]
iris_matrix <- as.matrix(iris_num) 
tsne_out_iris <- Rtsne(iris_matrix,perplexity = 15)

tsne_plot_iris <- data.frame(x = tsne_out_iris$Y[, 1],y = tsne_out_iris$Y[, 2])

plot <- plot(tsne_plot_iris)
tsne_iris <- ggplot(tsne_plot_iris) + ggtitle("iris, perplexity equals 15")

tsne_plot_iris <- as.numeric(unlist(tsne_plot_iris))
tsne_iris2 <- ggplot(tsne_plot_iris + geom_point(aes(x=x,y=y)) + ggtitle("iris, perplexity equals 15") + aes(color=iris$Species))

plot gives me a plot with black dots. tsne_iris and tsne_iris2 give me an empty plot, without anything, not even the title.

takeITeasy
  • 350
  • 3
  • 19
  • Related question: https://stackoverflow.com/questions/58593213/is-there-any-way-to-draw-umap-or-t-sne-plot-for-data-table/58595247#58595247 – teunbrand May 20 '20 at 11:12
  • This feels like a simple syntax error: you should not put every layer (geom_point for example) in the call to `ggplot()`, but append it with the `+` operator. To adress the colouring bit, you could add the `iris$Species` as a column in `tsne_plot_iris` and set `aes(..., colour = that_column)` in either the main `ggplot()` call or `geom_point()`. – teunbrand May 20 '20 at 11:18
  • There is simply no category contained in your data (it's column 5 which you filtered out in line 2). This is not a `plot` problem, but rather how to correctly apply `Rtsne` to stratified data. – jay.sf May 20 '20 at 11:37
  • When I do not filter out the Specy column the plot is empty even though @jay.sf. – takeITeasy May 20 '20 at 11:56
  • ```tsne_iris``` gives me an empty plot, too. And there I did it right. But thank you for mentioning ```ggplot()```errors @teunbrand – takeITeasy May 20 '20 at 11:57

0 Answers0