在地上绘制多条线 [英] Plotting multiple lines on plotly
本文介绍了在地上绘制多条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
头(测试版)
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)
但是如何添加多个y轴?
but how to add multiple y-axis?
推荐答案
这是您想要的吗?
df1 = stack(betas)
plot_ly(df1,y=values,group=ind)
p
或
p <- plot_ly(betas,y=historical_beta)
p <- add_trace(p,y=implied_beta)
p
或者如果您确实要说2个y轴:
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.
这篇关于在地上绘制多条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文