I am currently trying to plot subplots of differents datas.
I need the code to plot the different figures exactly the way I want them without me having to modify them after.
I have a problem with a 3D plot overlapped with the other plot in a subplot, as you can see here :
I need to manualy resset it (by using the zoom, pan and turntable rotation of the plotly display) in order to have it the way I like, that way (approximately) :
How can I automatize this process through the code ? I have been reading documentation for a while and can't find anything that might do the job.
Thank you very much !
You can find the code I am using below :
dataresults1ab <- read.table("./Datas/dataresults1ab.txt")
dataresults1c <- read.table("./Datas/dataresults1c.txt")
dataresults1d <- read.table("./Datas/dataresults1d.txt")
Fig1a <- {plot_ly(dataresults1ab,x= ~time,y= ~N1,name = "Species 1", type = "scatter", mode = "lines") %>%
add_trace(y= ~N2, name = "Species 2", mode="lines") %>%
add_trace(y= ~N3, name = "Species 3", mode="lines")%>%
layout(title="Time course of the abundances of three species competing for three ressources",xaxis=list(title="Time (days)",range=c(0,200)),yaxis=list(title="Species abundances",range=c(0,50)))}
Fig1b<-{plot_ly(dataresults1ab, x = ~N1, y = ~N2, z = ~N3, type = "scatter3d", mode = "lines")%>%
layout(title="The corresponding limit cycle",
scene=list(xaxis=list(title="Species 1",range=c(0,50)),
yaxis=list(title="Species 2",range=c(0,50)),
zaxis=list(title="Species 3",range=c(0,50)),
camera=list(up=list(0,0.5,0.5))))}
Fig1c <- {plot_ly(dataresults1c,x= ~time,y= ~N1,name = "Species 1", type = "scatter", mode = "lines") %>%
add_trace(y= ~N2, name = "Species 2", mode="lines") %>%
add_trace(y= ~N3, name = "Species 3", mode="lines") %>%
add_trace(y= ~N4, name = "Species 4", mode="lines") %>%
add_trace(y= ~N5, name = "Species 5", mode="lines") %>%
add_trace(y= ~N6, name = "Species 6", mode="lines") %>%
layout(title="Small-amplitude oscilations of six species on three ressources",xaxis=list(title="Time (days)",range=c(0,15000)),yaxis=list(title="Species abundances",range=c(0,70)))}
Fig1d <- {plot_ly(dataresults1d,x= ~time,y= ~N1,name = "Species 1", type = "scatter", mode = "lines") %>%
add_trace(y= ~N2, name = "Species 2", mode="lines") %>%
add_trace(y= ~N3, name = "Species 3", mode="lines") %>%
add_trace(y= ~N4, name = "Species 4", mode="lines") %>%
add_trace(y= ~N5, name = "Species 5", mode="lines") %>%
add_trace(y= ~N6, name = "Species 6", mode="lines") %>%
add_trace(y= ~N7, name = "Species 7", mode="lines") %>%
add_trace(y= ~N8, name = "Species 8", mode="lines") %>%
add_trace(y= ~N9, name = "Species 9", mode="lines") %>%
layout(title="Large-amplitude oscilations of nine species on three ressources",xaxis=list(title="Time (days)",range=c(0,3000)),yaxis=list(title="Species abundances",range=c(0,40)))}
Fig1 <- {subplot(Fig1a,Fig1b,Fig1c,Fig1d,nrows=2,margin=0.1,titleY=T,titleX = T)%>%
layout(scene = list(domain = list(x = c(0.5,1), y = c(0.5,1))),
showlegend=F,
title="",
annotations = list(list(
x = 0,
y = 1,
text = "a)",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = F
),
list(
x = 0.6,
y = 1,
text = "b)",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = F
),
list(
x = 0,
y = 0.425,
text = "c)",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = F
),
list(
x = 0.6,
y = 0.425,
text = "d)",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = F
)))
}
You can find the data I am using here : https://drop.chapril.org/download/3a18d06ab9d7efe3/#rhJx3zXvPMWwfikWyIJaEQ
I didn't download all of that data. A small sample is usually more than enough. I created data; I used the same names, so this should migrate to your project pretty well.
I see that you had tried working with the up
setting. You were close. You needed the eye
. Depending on how you use this, it can cause you to zoom in and out, as well. So it's better to start small if you're not familiar with how it works.
My fake data:
library(tidyverse)
library(plotly)
dataresults1ab <- data.frame(time = 0:200) %>%
mutate(N1 = sin(time), N2 = cos(time), N3 = tan(time))
Figure B with your original code.
(Fig1b<-plot_ly(dataresults1ab, x = ~N1, y = ~N2, z = ~N3, type = "scatter3d", mode = "lines")%>% layout(title = "The corresponding limit cycle", scene = list(xaxis = list(title = "Species 1", range = c(0,50)), yaxis = list(title = "Species 2", range = c(0,50)), zaxis = list(title = "Species 3", range = c(0,50)), camera = list(up = list(0, 0.5, 0.5)))))
Modified figure B.
(Fig1b<-plot_ly(dataresults1ab, x = ~N1, y = ~N2, z = ~N3,
type = "scatter3d", mode = "lines")%>%
layout(title = "The corresponding limit cycle",
scene = list(xaxis = list(title = "Species 1", range = c(0,50)),
yaxis = list(title = "Species 2", range = c(0,50)),
zaxis = list(title = "Species 3", range = c(0,50)),
camera = list(eye = list(x = 2, y = 2, z = .1)))))
A slightly less aggressive adjustment of figure B.
(Fig1b<-plot_ly(dataresults1ab, x = ~N1, y = ~N2, z = ~N3,
type = "scatter3d", mode = "lines")%>%
layout(title = "The corresponding limit cycle",
scene = list(xaxis = list(title = "Species 1", range = c(0,50)),
yaxis = list(title = "Species 2", range = c(0,50)),
zaxis = list(title = "Species 3", range = c(0,50)),
camera = list(eye = list(x = 1.5, y = 1.5, z = .1)))))