I've created a plot in R that has multiple y axes on the same side. However the additional axes overlay the plot, and when the graph is more noisy it causes the issue.
This is what I have:

While what I need is something like this:

Sample code:
library(plotly)
ay <- list(
tickfont = list(color = "red"),
overlaying = "y",
side = "left",
title = "second y axis",
position = 0.1
)
p <- plot_ly() %>%
add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10") %>%
add_lines(x = ~2:4, y = ~1:3, name = "slope of 1", yaxis = "y2") %>%
layout(
title = "Double Y Axis", yaxis2 = ay,
xaxis = list(title="x")
)
p
To my knowledge, multiple y axes are not correctly managed in plotly for R and the only trick available to circumvent the above problem is to tune margin attributes, as proposed here.
library(plotly)
ay <- list(
tickfont = list(color = "red"),
overlaying = "y",
side = "left",
title = "second y axis",
anchor="free"
)
p <- plot_ly() %>%
add_lines(x = ~1:3, y = ~10*(1:3), name = "slope of 10") %>%
add_lines(x = ~2:4, y = ~1:3, name = "slope of 1", yaxis = "y2") %>%
layout(
title = "Double Y Axis", yaxis2 = ay,
xaxis = list(title="x"),
yaxis = list(showline = FALSE, side="left"),
margin=list(pad = 50, b = 90, l = 150, r = 90)
)
p

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With