3

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 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.