Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly colors setting don't work in subplot in R

I use plotly to make line_plot.

with code below:

p4=plot_ly(p4_data,x=~date,y=~Projection_Variance,type="scatter",mode ="lines",colors="blue",name = "a line",legendgroup ="f")%>%
add_trace(y=~Realized_yield,line = list(color = 'chocolate', width = 2),name="b line",legendgroup ="g")
p4=p4%>%layout(legend = list(orientation = 'h'),xaxis =list(title = ""),colorway=c("blue","chocolate"))

this code can generate the plot I want. and the color “blue” setting with “colors” works fine.

before

But when I add this plot with some other plot together.the color setting fialed. p1,p2 and p3 were similar plot with code blow

p1=plot_ly(p1_data,x=~date,y=~Projection_yield,type="scatter",mode ="lines",name = "Projection",line = list(color = 'blue'),legendgroup ="a")%>%
add_trace(y=~AB20_yield,line = list(color = 'red', width = 2, dash = 'dash'),name="AB20",legendgroup ="b")%>%
add_trace(y=~Good_Target,line = list(color = 'orange', width = 2, dash = 'dash'),name="Good Target",legendgroup ="c")%>%
add_trace(y=~Exciting_Target,line = list(color = 'lime', width = 2, dash = 'dash'),name="Exciting Target",legendgroup ="d")%>%
add_bars(y=~Realized_yield, marker = list(color = 'chocolate'),legendgroup ="e",name="Realized")
p1=p1%>%layout(legend = list(orientation = 'h'),xaxis =list(title = ""),
               yaxis =list(range=c(min(as.numeric(p1_data[p1_data!=0]),na.rm = T)*0.8,max(p1_data[,2:6])*1.02)))

subplot(p1,p2,p3,p4,nrows=2,margin = 0.05)

In the subplot, the color “blue” in p4 was set to something else. the color in p1~p3 was OK

after
I don’t know what’s going on. Can any one help me with it?