5th*_*5th 6 r colors plotly r-plotly
我有一个图,其中第一条迹线为灰色,该迹线将被其他颜色的迹线覆盖。我的问题是在plotly
4.7.1 版本中。以及 4.8.0 版本。我无法调整颜色。
一年前这段代码可以工作:
mysim=data.frame(x=rep(1:4,4),y=rbinom(16,10,0.5),id=rep(1:4,each=4))
my_colors<-c( ## add the standard plotly colors
'#1f77b4', #// muted blue
'#ff7f0e', #// safety orange
'#2ca02c', #// cooked asparagus green
'#d62728' #// brick red
)
plot_ly() %>%
add_trace(x=1:4,y=rbinom(4,10,0.4),type='scatter',mode='lines',
line=list(color='#CCCCCC',dash='dashed'),hoverinfo='skip',opacity=0.25) %>%
add_trace(data=mysim,x=~x,y=~y,type='scatter',mode='lines', split=~as.factor(id),
line=list(color=my_colors),hoverinfo='skip',opacity=1)
Run Code Online (Sandbox Code Playgroud)
遗憾的是我不再拥有那台机器了。plotly
但从那时起似乎发生了一些变化。我还尝试使用color
参数而split
不是colors
-listline
来指定颜色。它没有任何影响。我仍然明白这个情节:
我在这里缺少什么?我怎样才能让它发挥作用?
Sté*_*ent 10
看到这个问题。
如果您使用color
而不是并且如果您在函数开头使用参数split
设置颜色,则此方法有效:plot_ly
colors
plot_ly(colors=my_colors) %>%
add_trace(x=1:4,y=rbinom(4,10,0.4),type='scatter',mode='lines', line=list(color='rgb(0,0,255)',dash='dashed'),hoverinfo='skip',opacity=0.25) %>%
add_trace(data=mysim,x=~x,y=~y,type='scatter',mode='lines', color=~as.factor(id),
hoverinfo='skip',opacity=1)
Run Code Online (Sandbox Code Playgroud)