# Load libraries
library(Rtsne)
library(mlbench)
library(ggthemes)
library(plotly)
library(dplyr)

# Load 'Vehicle' data from mlbench package (4 Classes)
data(Vehicle)

# Run t-SNE with a seed for reproducibility
set.seed(1234)
tsne_out <- Rtsne(X = as.matrix(Vehicle[,1:18]), dims = 3, max_iter = 1000)

# Prepare a data frame for plotting
d_tsne <- data.frame(tsne_out$Y, Class = Vehicle$Class)
colnames(d_tsne) <- c("x", "y", "z", "Class")

# Create a 3D Scatter plot using plotly
p <- 
  plot_ly(d_tsne, x = x, y = y, z = z, type = "scatter3d", group = Class, mode = "markers") %>%
  layout(title = "t-SNE on 'Vehicle'")
p