1 | initial version |
To create a 3D Tri-Surf plot in R using plotly and incorporate a color legend, follow these steps:
library(plotly)
library(ggplot2)
data(volcano)
x <- 1:nrow(volcano)
y <- 1:ncol(volcano)
z <- as.matrix(volcano)
df <- data.frame(x = rep(x, each = length(y)),
y = rep(y, length(x)),
z = as.vector(z))
p <- ggplot(df, aes(x, y, z = z, fill = z)) +
geom_tile(aes(width = 1, height = 1)) +
scale_fill_gradient(low = "blue", high = "red", na.value = "white")
p <- ggplotly(p)
p %>%
layout(scene = list(xaxis = list(title = "X-axis"),
yaxis = list(title = "Y-axis"),
zaxis = list(title = "Z-axis")),
colorbar = list(title = "Height",
tickvals = c(100, 150, 200, 250),
ticktext = c("100", "150", "200", "250")))
This will create a 3D Tri-Surf plot with a color legend that shows the height values of each point in the plot.