Multiple bar chart issue with loop

Hi everyone,
I’m facing a issue while drawing a multiple bar chart. I have followed topics of plotly but there is something wrong with my code :

for (i in 3:7){ 
  data_graph=data.frame(liste_modalite, R1[,i],R2[,i],R3[,i])
        a<-plot_ly(data = data_graph, x=~liste_modalite, y = ~R1[,i], type = 'bar', name = 'R1') %>%
        add_trace(y= ~R2[,i], name ='R2') %>%
        add_trace(y= ~R3[,i], name ='R3') %>%
        layout(yaxis = list(title = names(R1[i])), barmode ='group') 
        assign(paste("Graph_", names(R1[i]), sep=""), a)

In fact, it seems that the issue is about the “data_graph”. When I include a print(data_graph) and a View(data_graph) in the loop the result is not the same. The view command shows only the last result of the loop instead of the print command wich shows the good data frame for each iteration.
So graphs of each iteration are similar to the last one…

May someone could help me, I don’t undestand =’(

See you soon and thanks for reading !

I have found the solution. The issue came from de “~” just befor the lists R1, R2, R3 !!

Thanks =)

1 Like