I have a data frame which consists of 4 variables A, B, C, D, I need to plot 3D surface plot for x = A, y = B, z = C. My problem is the plot should contain 3 surfaces which is with respect to the values in D i.e D has values of 0,1 and -1 I need to have 3 surfaces for 3 different values of D.
I tried by sub setting the data frame into 3 different dataframes with respect to the values of D and adding surface to plot_ly function but it doesnt seem to work and I am getting blank graph. I don't know if I am using the right plot function.
Below is my data frame d1
A B C D
734.5 2.28125 3.363312755 0
738 2.53125 3.395864326 0
727.25 2.484375 3.41183431 1
737 2.421875 3.380499188 1
727.25 2.3828125 3.39538442 1
933.25 4.6875 3.148660474 1
932.75 4.671875 3.155840809 1
934 4.671875 3.165391107 1
920.75 4.671875 3.194808475 1
913.25 4.671875 3.22907393 1
896.75 4.671875 3.287157844 1
880 4.671875 3.341203642 -1
866.75 4.59375 3.388017143 -1
714.5 3.296875 3.572828317 -1
730.75 3.296875 3.535364241 -1
734.75 3.296875 3.526142314 -1
713.25 3.7734375 3.653888449 -1
711.75 3.8203125 3.665152882 -1
711.75 3.8125 3.65967422 -1
714 3.796875 3.630867839 0
754.25 3.796875 3.560165628 0
715.25 3.78125 3.650415301 0
Below is my R code
library(plotly)
pd1 <- subset(d1, (D == 1))
nd1 <- subset(d1, (D == -1))
zd1 <- subset(d1, (D == 0))
p <- plot_ly(showscale = FALSE) %>%
add_surface(x= pd1$A,y = pd1$B, z = pd1$C)%>%
add_surface(x= nd1$A,y =nd1$B, z = nd1$C)%>%
add_surface(x= zd1$A,y =zd1$B, z = zd1$C)%>%