I'm trying to plot many traces on the same figure, thus needing to use a loop but it doesn't work, as you can see in the example below :
Fig3abis<-plot_ly(data=dataresults3ab,x=dataresults3ab[[1]])
for(j in c(100,500,1000,1500))
{
#print(dataresults3ab[,j])
Fig3abis <- add_trace(Fig3abis,
y=~dataresults3ab[,j],
name=paste("N1",as.character(j),sep = "_"),
type="scatter",
mode="markers",
marker=list(size=4,color="black"))
}
Fig3abis <- Fig3abis%>% layout(title="Bifurcation diagram for five species competing for five resources. Local minima and maxima of species 1,
from t=2,000 to t=4,000 days, as a function of the half-saturation constant K41",
showlegend=F,
xaxis=list(title="Half-saturation constant K41, of species 1",range=c(0.1,0.5)),
yaxis=list(title="Abundancie of species 1",range=c(0,100)))
As you can see there is a problem : the plot only show the last added trace.
When I try to plot each trace one by one, it works really well, as you can see bellow :
Fig3a <- plot_ly(data=dataresults3ab,x=dataresults3ab[[1]])
Fig3a <- add_trace(Fig3a,
y=~dataresults3ab[,100],
name="N1_2",
type="scatter",
mode="markers",
marker=list(size=4,color="black"))%>%
add_trace(Fig3a,
y=~dataresults3ab[,500],
name="N_3",
type="scatter",
mode="markers",
marker=list(size=4,color="black"))%>%
add_trace(Fig3a,
y=~dataresults3ab[,1000],
name="N1_4",
type="scatter",
mode="markers",
marker=list(size=4,color="black"))%>%
add_trace(Fig3a,
y=~dataresults3ab[,1500],
name="N1_5",
type="scatter",
mode="markers",
marker=list(size=4,color="black"))
Fig3a <- Fig3a%>% layout(title="Bifurcation diagram for five species competing for five resources. Local minima and maxima of species 1, from t=2,000 to t=4,000 days, as a function of the half-saturation constant K41",
showlegend=F,
xaxis=list(title="Half-saturation constant K41, of species 1",range=c(0.1,0.5)),
yaxis=list(title="Abundancie of species 1",range=c(0,100)))
I've been looking for solution for quite a while and this is not the first time this problem is submitted but none of the different answers worked for me (using evaluate for example)
Note: here I used a small loop and a small sample of traces but in the end I'd like to plot around 8000 traces.
The data I used is a simple data frame with the first column displaying the x axis and all of the other represent each trace that needs to be plotted