简体   繁体   中英

Resizing plots in plotly (R)

Sorry if this question has already been answered but I can't find a solution.

I have a data frame which is imported from a .csv file. It has four columns. I want to plot a 3d scatter plot of the first two columns against the last column using Plotly.

The problem is that for some reason, the scatter plot does not automatically resize its axes to fit the plot space. So in this case I end up with a tall thin plot. The weird thing is that if I do an example with some random numbers, I don't get this problem.

Can anyone help me to get my scatter plot to fit to the window?

My data can be found at https://www.dropbox.com/s/ojwrezjker33x2b/Data.csv?dl=0

Basically I want to do:

library(plotly)
X<-read.csv("Data.csv")
plot_ly(x=X[,1],y=X[,2],z=X[,4],type='scatter3d',mode='markers')

And this results in a tall and thin scatter plot (sorry can't post an image cos I am new to the site).

I would like this to be a well-proportioned scatter plot that fits the window.

Thanks for any help.

The default setting for aspectmode is 'auto' and Plotly will try to keep the relative axis lenghts equal.

If you set aspectmode='cube' you should get a plot with identical absolute axes lengths.

plot_ly(x=X[,1],y=X[,2],z=X[,4],type='scatter3d',mode='markers') %>% 
    layout(scene=list(aspectmode='cube'))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM