✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Plotly 3 y axis overlap issue

Hi there,
I am trying to plot multiple axis in R. I manage to get all the 3 y axis to plot (with a lot of guidance from other peoples questions/comments on the forum) but I am not sure how to get the 3rd y-axis to not overlay on top of the 2nd y-axis. I read that I should use margins to do this but I have been playing around with pad, l, r, b and they all still overlay. I also tried position but then it moves it into the figure. Is there any advice I could get on how to get the 3rd y-axis to plot behind the 2nd y axis?

Thank you!

a_axis <- list(
tickfont = list(color = “green”),
overlaying = “y”,
side = “right”,
title = “a”,
showgrid = FALSE,
showline = T,
ticks = “outside”
)

b <- list(
tickfont = list(color = “red”),
overlaying = “y”,
side = “right”,
title = “b”,
showgrid = F,
showline = T,
ticks = “outside”,
anchor = “free”,
position = 1)

t <- list(
#family = “sans serif”,
size = 12,
color = ‘black’)

(p <- plot_ly() %>%
add_lines(x = ~df$Month, y = ~df$c, name = “c”, line = list(color = ‘black’, width = 2)) %>%
add_lines(x = ~df$Month, y = ~df$a, name = “a”, yaxis = “y2”, line = list(color = ‘green’, width = 2)) %>%
add_lines(x = ~df$Month, y = ~df$b, name = “b”, yaxis = “y3”, line = list(color = ‘red’, width = 2)) %>%
layout(legend = list(x =1.1, y = 1)) %>%
layout(
title = “”, yaxis2 = a_axis, yaxis3 = b, font = t,
xaxis = list(title=“Month”, showgrid=F, showline =T, ticks = “outside”),
yaxis = list(title=“c”, showgrid=F, showline =T, ticks = “outside”),
margin = list(pad = 10, b = 40, l = 40, r = 40)
))