3D Animation help in R

I have read the following article:

and I am still lost when it comes to programming a specific “spin” to a chart.

I am designing a cube that will spin to a predetermined position based on buttons.

My code is below:

devtools::install_github("ropensci/plotly")
library(plotly)
x = c(0, 0, 1, 1, 0, 0, 1, 1)
y = c(0, 1, 1, 0, 0, 1, 1, 0)
z = c(0, 0, 0, 0, 1, 1, 1, 1)
i = c(7, 0, 0, 0, 4, 4, 2, 6, 4, 0, 3, 7)
j = c(3, 4, 1, 2, 5, 6, 5, 5, 0, 1, 2, 2)
k = c(0, 7, 2, 3, 6, 7, 1, 2, 5, 5, 7, 6)

#Define styling <- here is the issue
restyle <-  list(method = "relayout",
                 args = list(list(scene.camera.eye.x=2,scene.camera.eye.y=2,scene.camera.eye.z = 1 )),
                 label = "relayout")

relayout <- list(method = "relayout",
                 args = list(list(scene.eye.x=1,scene.eye.y=1,scene.eye.z = 2 )),
                 label = "relayout2")


font.pref <- list(size=13,family="Arial, sans-serif",color="black")
x.list <- list(title = "x",titlefont = font.pref)
y.list <- list(title = "y",titlefont = font.pref)
z.list <- list(title = "z",titlefont = font.pref)


p <- plot_ly(type = 'mesh3d',hoverinfo = "none",
             x = x,
             y = y,
             z = z,
             i = i,
             j = j,
             k = k,facecolor = rep(toRGB(viridisLite::inferno(6)), each = 2)) %>%
  layout(scene=list(xaxis = x.list,
                    yaxis = y.list,
                    zaxis = z.list), updatemenus = list(list(type = 'buttons',direction = "right",
                              yanchor = "bottom", buttons = list(restyle, relayout))))
p

The buttons show up on the graph but nothing happens when i click them. I believe the issue is how i am defining the “camera”.

Any help would be greatly appreciated.

I can replicate your image and buttons, and I can control the camera explicitly, but I’m afraid I’ve never tried adding buttons to plots, so I won’t be much help I don’t think.

Are you trying to emulate an example from somewhere? Isthis definitely something that can be done via custom buttons

@joehealey,

I am not completely sure it is possible in R, but I have seen examples in plotly.js for 3D charts.

For r specifically, it is possible for 2D charts to be moved in a similar fashion.