1

I have a 3D scatter plot (plot_ly) that has all the axes of the same length by default - different scale, of course. I want to stretch along one axis (x), is there a way to do this?

Sample code using mtcars:

> plot_ly(mtcars, x = ~ wt, y = ~ disp, z = ~mpg, 
          type = "scatter3d", mode = "marker", opacity = 0.6)

I can zoom, or rotate the plot but I want the default x-axis to be twice as long as the y and z axes.

default result

Gautam
  • 2,597
  • 1
  • 28
  • 51
  • Maybe `aspectratio` can do the trick? See the [plotly manual](https://plot.ly/r/reference/#layout-scene-aspectmode). – csgroen Apr 05 '18 at 14:21
  • Thanks! How/where do I add this? I've tried adding it to the main command without success. Having trouble finging proper poltly documentation, their website does not explain the basics of their package much. – Gautam Apr 05 '18 at 17:25
  • Apparently `aspectratio` is not an attribute of a `scatter3d` plot. I'm not well versed in plotly either, but maybe using a layout can help. – csgroen Apr 05 '18 at 17:55

1 Answers1

2

Maybe you could try this:

plot_ly(mtcars, x = ~ wt, y = ~ disp, z = ~mpg, 
        type = "scatter3d", mode = "marker", opacity = 0.6) %>% 
layout(scene = list(aspectmode = "manual", aspectratio = list(x=1, y=0.2, z=0.2)))

Just adjust the aspectratio as you wish.

MLavoie
  • 9,671
  • 41
  • 36
  • 56