R plotly 3D Surface Plot Problem

I tried to draw a three-dimensional surface map based on these plotly examples

When I tried these examples on my data set

test_plotly = structure(list(Age = c(82L, 82L, 83L, 83L, 83L, 81L, 
81L,
81L, 79L, 80L, 82L, 78L, 78L, 79L, 78L, 80L, 79L, 77L, 77L, 77L,
77L, 78L, 76L, 77L, 77L, 78L, 77L, 76L, 83L, 79L, 76L, 84L, 75L,
75L, 77L, 74L, 74L, 75L, 74L, 74L, 73L, 73L, 74L, 81L, 84L, 73L,
72L, 73L, 71L, 71L, 73L, 72L, 79L, 72L, 71L, 76L, 72L, 75L, 73L,
71L, 70L, 79L, 69L, 70L, 70L, 70L, 77L, 69L, 69L, 68L, 69L, 73L,
69L, 69L, 74L, 68L, 69L, 70L, 74L, 68L, 68L, 68L, 68L, 68L, 68L,
80L, 69L, 72L, 80L, 80L, 81L, 81L, 67L, 66L, 67L, 78L, 77L, 67L,
67L, 81L), BMI = c(32.88, 30.79, 30.08, 30.08, 30.08, 30.08,
30.08, 30.08, 36.86, 36.86, 32.33, 43.17, 43.17, 26.89, 25.15,
24.59, 33.98 , 27.83, 34.66, 33.81, 29.47, 23.54, 23.54, 30.29,
43.21, 33.03, 20.62, 41.41, 37.88, 25.58, 26.08, 3 1.18, 27.78,
23.35, 25.42, 27.75, 27.75, 28.83, 27.68, 27.14, 29.13, 27.23,
27.75, 25.25, 28.79, 34.46, 30.93, 22.57, 19.06, 27.81, 33.35,
28.63, 36.11, 37.94, 31.89, 31.23, 38.65, 23.39, 31.13, 31.13,
24.07, 27.01, 32.78, 37.82, 31.98, 28.77, 27.52, 32.88, 26.17,
46.24, 32.09, 32.78, 25.4, 32.72, 31.21, 29.13, 45.85, 27.99,
36.33, 32.21, 35.97, 28.88, 26.12, 26.31, 32.61, 32.08, 36.58,
31.53, 42.84, 42.84, 42.84, 42.84, 31.68, 54.27, 30.26, 29.33,
29.33, 31.53, 32.66, 36.82), Task_Completion_Time = c(25L,
19L, 25L, 38L, 38L, 25L, 38L, 38L, 16L, 16L, 32L , 39L, 49L, 33L,
9L, 20L, 29L, 25L, 46L, 27L, 24L, 24L, 24L, 18L, 52L, 23L, 20L,
31L, 45L, 27L, 24L, 10L , 18L, 77L, 40L, 26L, 10L, 37L, 39L, 21L,
11L, 26L, 23L, 39L, 31L, 13L, 44L, 20L, 40L, 30L, 24L, 11L, 30L,
28L, 34L, 26L, 53L, 16L, 10L, 10L, 22L, 15L, 32L, 50L, 52L, 18L,
27L, 21L, 36L, 23L, 17L, 20L, 34L, 27L, 47L, 38L, 47L, 53L, 48L,
21L, 15L, 19L, 45L, 20L, 11L, 35L, 27L, 17L, 30L, 88L, 30L, 88L,
18L, 41L, 24L, 25L, 25L, 40L, 19L, 16L)), .Names = c("Age",
"BMI", "Task_Completion_Time"), class = c("data.table",
"data.frame"), row.names = c(NA, -100L))

I received an error

Error in function_list[[k]](value): 
could not find function "add_surface"

The best I can do is something like this

plot_ly(z = as.numeric(test_plotly$Age), y = as.numeric(test_plotly$Task_Completion_Time), x = as.numeric(test_plotly$BMI))

But this is confusing , There is no example of plot surface plot.

enter image description here

I don’t know what I am missing, any help to fix this problem and generate a clean 3D surface map is very much appreciated.

add_surface needs x and y to form a grid, and z needs to be a matrix on the grid.
If you don’t know exactly what your data is and what you want to do, I can only guess how Do this:

library(akima)

# interpolate data o nto grid
test_plotly <- with(test_plotly, interp(Age, BMI, Task_Completion_Time,
duplicate = "mean"))

# plot surface over grid
plot_ly (x = test_plotly$x, y = test_plotly$y, z = test_plotly$z,
type = "surface")

will give you surface plot

I tried to draw a three-dimensional surface map based on these plotly examples

When I tried these examples on my dataset

test_plotly = structure(list(Age = c(82L, 82L, 83L, 83L, 83L, 81L, 
81L,
81L, 79L, 80L, 82L, 78L, 78L, 79L, 78L, 80L, 79L, 77L, 77L, 77L,
77L, 78L, 76L, 77L, 77L, 78L, 77L, 76L, 83L, 79L, 76L, 84L, 75L,
75L, 77L, 74L, 74L, 75L, 74L, 74L, 73L, 73L, 74L, 81L, 84L, 73L,
72L, 73L, 71L, 71L, 73L, 72L, 79L, 72L, 71L, 76L, 72L, 75L, 73L,
71L, 70L, 79L, 69L, 70L, 70L, 70L, 77L, 69L, 69L, 68L, 69L, 73L,
69L, 69L, 74L, 68L, 69L, 70L, 74L, 6 8L, 68L, 68L, 68L, 68L, 68L,
80L, 69L, 72L, 80L, 80L, 81L, 81L, 67L, 66L, 67L, 78L, 77L, 67L,
67L, 81L) , BMI = c(32.88, 30.79, 30.08, 30.08, 30.08, 30.08,
30.08, 30.08, 36.86, 36.86, 32.33, 43.17, 43.17, 26.89, 25.15,
24.59, 33.98, 27.83, 34.66 , 33.81, 29.47, 23.54, 23.54, 30.29,
43.21, 33.03, 20.62, 41.41, 37.88, 25.58, 26.08, 31.18, 27.78,
23.35, 25.42, 27.75, 27.75, 28.83, 27.68, 27.14 , 29.13, 27.23,
27.75, 25.25, 28.79, 34.46, 30.93, 22.57, 19.06, 27.81, 33.35,
28.63, 36.11, 37.94, 31.89, 31.23, 38.65, 23.39, 31.13, 31.13, < br /> 24.07, 27.01, 32.78, 37.82, 31.98, 28.77, 27.52, 32.88, 26.17,
46.24, 32.09, 32.78, 25.4, 32.72, 31.21, 29.13, 45.85, 27.99,
36.33, 32.21 , 35.97, 28.88, 26.12, 26.31, 32.61, 32.08, 36.58,
31.53, 42.84, 42.84, 42.84, 42.84, 31.68, 54.27, 30.26, 29.33,
29.33, 31.53, 32.66, 36.82), Task_Completion_Time = c(25L,
19L, 25L, 38L, 38 L, 25L, 38L, 38L, 16L, 16L, 32L, 39L, 49L, 33L,
9L, 20L, 29L, 25L, 46L, 27L, 24L, 24L, 24L, 18L, 52L, 23L, 20L,
31L, 45L, 27L, 24L, 10L, 18L, 77L, 40L, 26L, 10L, 37L, 39L, 21L,
11L, 26L, 23L, 39L, 31L, 13L, 44L, 20L, 40L, 30L, 24L, 11L, 30L,
28L, 34L, 26L, 53L, 16L, 10L, 10L, 22L, 15L, 32L, 50L, 52L, 18L,
27L, 21L, 36L, 23L, 17L, 20L, 34L, 27L, 47L, 38L, 47L, 53L, 48L,
21L, 15L, 19L, 45L, 20L, 11L, 35L, 27L, 17L, 30L, 88L, 30L, 88L,
18L, 41L, 24L, 25L, 25L, 40L, 19L, 16L)), .Names = c("Age",
"BMI", "Task_Completion_Time"), class = c("data .table",
"data.frame"), row.names = c(NA, -100L))

I received an error

Error in function_list[[k]](value): 
could not find function "add_surface"

The best I can do is something like this

plot_ly(z = as.numeric(test_plotly$Age), y = as.numeric(test_plotly$Task_Completion_Time), x = as.numeric(test_plotly$BMI))

But this is very confusing, there is no example of the surface plot like the plot.

enter image description here

Don’t know what I’m missing, any help to fix Thank you very much for this question and generating a clean 3D surface map.

add_surface needs x and y to form a grid, and z needs to be a matrix on the grid .
If you don’t know exactly what your data is and what you want to do, I can only guess how to do it:

library(akima )

# interpolate data onto grid
test_plotly <- with(test_plotly, interp(Age, BMI, Task_Completion_Time,
duplicate = "mean"))

# plot surface over grid
plot_ly(x = test_plotly$x, y = test_plotly$y, z = test_plotly$z,
type = "surface")

will give Yousurface plot

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1484 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.