massisenergy
massisenergy

Reputation: 1820

Cannot create a 3D surface using plot_ly

MWE: a dataframe shown below.

"TVF" "minEuler" "E_avg"
29.63 -12 3.65
30.00 -26 3.311
30.24 -72 8.247
30.82 -47 13.02
20.25 -6 2.085
14.53 -32 2.154
14.66 -1 1.44
24.12 -82 6.784
21.25 -35 4.309
25.82 -17 2.697
26.15 -42 2.832
18.38 -29 2.038
18.51 -80 5.514
14.67 -58 1.91
20.40 -166 2.786
26.50 -69 6.794
40.97 -12 24.852
18.98 -102 3.107
19.15 -75 3.85
40.54 -48 16.347
35.09 -41 18.847
28.15 -73 5.963
40.25 -94 21.82
24.28 -53 6.245
30.34 -42 25.578

CODE:

plot_ly(x = S_TVF_Euler_E_axes$TVF, y = S_TVF_Euler_E_axes$minEuler, 
        z = S_TVF_Euler_E_axes$E_avg, type = 'surface')

OUTPUT:

No surface is created

GOAL: Fit a surface to the scatter plot (or directly plot a surface). I could plot the scatterplot using plot_ly but the surface isn't working. I have tried also this, which did not work for me.

I am new to 3D plots and any help or hint is greatly appreciated!

Upvotes: 1

Views: 135

Answers (1)

massisenergy
massisenergy

Reputation: 1820

As explained by s_t, we need to have a matrix for plotting the surface. I tried a little different way, using the interp function from the package akima. I got the idea from the answer by "mschilli" here.

> S_TVF_Euler_E_axes_plotly <- with(S_TVF_Euler_E_axes, interp(TVF, 
                                  minEuler, E_avg, duplicate = "mean"))
> plot_ly(x = S_TVF_Euler_E_axes_plotly$x, y = S_TVF_Euler_E_axes_plotly$y, 
        z = S_TVF_Euler_E_axes_plotly$z, type = 'surface')

Surface only

Now, I am worried if my surface is right or wrong, it doesn't match at all to the solution provided by s_t!

Upvotes: 1

Related Questions