1

Is it possible to generate a 3D plot from models using plotly? I tried to search over the internet, but many examples are based on the infamous volcano dataset that generates a plot from a matrix of points.

My two models are:

y = 0.49867x - 4.78577

y = 76.13084x + 4.81945

If not possible, how can i transform my data into the matrix format such as that in the volcano dataset? For more details, I have hosted the data file here. I have never used plotly before and i'm unfamiliar with the grammar, but i think i can manage if i can at least format my data into the likes of the volcano dataset.

Thank you.

0

1 Answer 1

1

To plot a surface with plotly, you need to construct a numeric matrix.

Taking Himmelblau's function as a test:

f <- function(x, y) { (x^2+y-11)^2 + (x+y^2-7)^2 }

Create x and y values:

x <- seq(-6, 6, length = 100)
y <- x

Then, create z with outer function. It will return a matrix.

z <- outer(x, y, f)

We can now create a surface plot:

library(plotly)
plot_ly(x = x, y = y, z = ~z) %>% add_surface()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.