Gautam
Gautam

Reputation: 2753

Stretch axes in plotly 3D plot R

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

Upvotes: 1

Views: 2631

Answers (1)

MLavoie
MLavoie

Reputation: 9836

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.

Upvotes: 2

Related Questions