Install and load necessary packages

install.packages(“plotly”) install.packages(“dplyr”) install.packages(“utils”) library(plotly) library(dplyr) library(utils) # Create a sample dataset data <- data.frame( x = rnorm(100), y = rnorm(100), z = rnorm(100), category = sample(letters[1:3], 100, replace = TRUE) )

Inspect the dataset

head(data)

Create a sample dataset

data <- data.frame( x = rnorm(100), y = rnorm(100), z = rnorm(100), category = sample(letters[1:3], 100, replace = TRUE) )

Inspect the dataset

head(data) # Create a scatter plot using Plotly plot <- plot_ly( data = data, x = ~x, y = ~y, z = ~z, color = ~category, type = ‘scatter3d’, mode = ‘markers’ )

Display the plot

plot

Save the plot as an HTML file

htmlwidgets::saveWidget(plot, “interactive_scatter_plot.html”)