Plotting multiple lines on plotly

大憨熊 提交于 2019-12-24 00:43:23

问题


head(betas)

           historical_beta implied_beta
2015-11-05       0.4876163    0.4558767
2015-11-06       0.4828677    0.4856059
2015-11-09       0.4628628    0.4369807
2015-11-10       0.4636145    0.4492920
2015-11-11       0.4511203    0.4558034
2015-11-12       0.4418248    0.4175937

Now I have to plot both timeseries on the same graph. I know

plot_ly(y=betas$historical_beta)

but how to add multiple y-axis?


回答1:


Does this do what you want?

df1 = stack(betas)
plot_ly(df1,y=values,group=ind)
p

or

p <- plot_ly(betas,y=historical_beta)
p <- add_trace(p,y=implied_beta)
p

or in case you really meant 2 y axes:

ay <- list(
  tickfont = list(color = "red"),
  overlaying = "y",
  side = "right"
)
p <- plot_ly(betas,y=historical_beta,name="Historical Beta") %>%
       add_trace(y=implied_beta,name="Implied Beta",yaxis="y2") %>%
       layout(yaxis2=ay)
p

The first one does a nicer job of automatically labeling the traces.



来源:https://stackoverflow.com/questions/34140473/plotting-multiple-lines-on-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!