plot3d in r

# Install and load the 'rgl' package for 3D plotting
install.packages("rgl")
library(rgl)

# Create sample data
x <- y <- seq(-5, 5, length.out = 100)
z <- outer(x, y, function(x, y) sin(sqrt(x^2 + y^2)))

# Create a 3D scatter plot
plot3d(x, y, z, type = "n", xlab = "X-axis", ylab = "Y-axis", zlab = "Z-axis", main = "3D Scatter Plot")

# Add points to the 3D plot
points3d(x, y, z, col = "blue", size = 2)

# Add a wireframe surface to the plot
surface3d(x, y, z, color = "green")

# Add a color legend
rgl.postscript("plot3d.png", fmt = "png", params = c(bgcolor = "white"))