plotly colors setting don't work in subplot

hello everyone
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 ="d=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"))

The color setting with "colors" works fine.

But when I add this plot with some other plot together.the color setting fialed.
subplot(p1,p2,p3,p4,nrows=2,margin = 0.05)
the p1 p2 p3 are similar plot with code like this

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)))

after

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

colors all have to be lower case e.g. chocolate. Also plotly might not recognise all R colors. If it doesn't recognise it, it will ignore it. Also spell color correctly, no s on the end. Check what colors plotly understands.

https://community.plotly.com/t/plotly-colours-list/11730/3

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

colors="blue"

I don't think this is actually working. i think blue is just the default color and it's ignoring colors because it's not a known argument. When you have subplots then the default color changes.

https://plotly.com/r/reference/

thank you for your suggestion.
and sorry about my misleading discription.
my main error is the color set "blue" in the P4. It works when I only plot this figure, but fails when I add p4 into a subplot.

Check out the documentation for plot_ly. Looks like it needs to be color = I("blue"). color actually refers to the fill color, but stroke (the line color) picks up the same value by default.

You are right.
what parameter should I change?
I have try set line=list(color="blue") but it failed.
do you have any idea?
Thank you