How to specify camera perspective of 3d plotly chart in R?

后端 未结 2 1506
悲&欢浪女
悲&欢浪女 2021-01-18 02:05

I would like to change the default camera perspective of my plotly 3d scatter plot, it is not clear from the help how this should be done. I understand the layout parameters

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 03:01

    This is a little late but hopefully this helps others looking for a solution to this. Here's an example:

    library(plotly)
    set.seed(123)
    
    # Create Random Data
    ds <- diamonds[sample(1:nrow(diamonds), size = 1000),]
    
    scene = list(camera = list(eye = list(x = -1.25, y = 1.25, z = 1.25)))
    
    plot_ly(ds, x = carat, y = cut, z = price, group = color, type = "scatter3d", mode = "markers",
            marker = list(opacity = 0.6, size = 4)) %>% 
      layout(title = "3D Scatter plot", scene = scene)
    

提交回复
热议问题