I have this R code which makes a 3D plot in plotly:
library(plotly)
x <- seq(-5, 5, length.out = 100)
y <- seq(-5, 5, length.out = 100)
grid <- expand.grid(x = x, y = y)
z <- with(grid, sin(sqrt(x^2 + y^2))/sqrt(x^2 + y^2 + 1) + cos(x*y/4)/2)
z_matrix <- matrix(z, nrow = length(x), ncol = length(y))
plot_ly(x = x, y = y, z = z_matrix) %>%
add_surface(
contours = list(
z = list(
show = TRUE,
usecolormap = TRUE,
highlightcolor = "#ff0000",
project = list(z = TRUE)
)
)
) %>%
layout(
title = "3D Mathematical Wave Function",
scene = list(
camera = list(
eye = list(x = 1.5, y = 1.5, z = 1.5)
),
xaxis = list(title = "X"),
yaxis = list(title = "Y"),
zaxis = list(title = "Z")
)
)
I am trying to make this above plot ONLY in ggplot
I have seen other 3d plotting libraries in R (e.g. https://cran.r-project.org/web/packages/rgl/index.html), but is it possible to make this plot exclusively using ggplot?