简体   繁体   English

在地上绘制多条线

[英]Plotting multiple lines on plotly

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? 但是如何添加多个y轴呢?

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: 或者如果您确实要说2个y轴:

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. 第一个在自动标记迹线方面做得更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM