Orthographic projection of 3d plots in R (plotly)

Viewed 328

I am trying to plot in 3d some data with plotly. However, I do not want the standard perspective that is given, instead I'm looking for orthographic projection (i.e. distance between points further away does not get smaller). I have already tried to change the layout.scene.camera parameter projection (see code below, provided with example data), but it has not worked. I would appreciate any advice on how to do this.

fig2 <- plot_ly(iris,x =~Sepal.Length, y=~Sepal.Width, z=~Petal.Length,  
              marker = list(size = 2),  color = ~Petal.Width) %>% 
              layout(scene = list(camera =list(projection='orthographic'),
            aspectmode = "manual", aspectratio = list(x=1, y=5,z=0.5)))%>% 
            add_markers()
1 Answers

You just need to put the value for projection also in a named list. Reference: https://plotly.com/r/reference/layout/scene/#layout-scene-camera-projection

Replace projection='orthographic' with projection=list(type = 'orthographic').

plot_ly(iris, x = ~Sepal.Length, y = ~Sepal.Width, z = ~Petal.Length,  
        marker = list(size = 2), color = ~Petal.Width) %>% 
  layout(
    scene = list(camera = list(projection = list(type = 'orthographic')), 
    aspectmode = "manual", 
    aspectratio = list(x=1, y=5,z=0.5))
    ) %>% 
  add_markers()
Related