I want to show data on a secondary y axis using plotly. unfortunately, no ticks are showing.
What needs to be set so that I can show the minimum, maximum, and display ticks every 5 units? In this example, I would like to see val2 axis showing ticks at 5, 10 (5 is the smallest multiple of 5 < min value of val2/val3 columns, and 10 is the smallest multiple of 5 > max value) in the green box.
It is odd, as the primary y-axis shows and scales it fine
code used to generate:
data = structure(list(Quarter = c("Q1-19", "Q2-19", "Q3-19", "Q4-19", "Q1-20",
"Q2-20", "Q3-20", "Q4-20", "Q1-21", "Q2-21", "Q3-21", "Q4-21",
"Q1-22"), val1 = c(-0.104, -0.069, -0.075, 0.1, -0.15,
-0.05, -0.0825, 0, 0, 0, 0, 0, 0), val2 = c(8.14554910547994,
8.55275717435675, 8.40632494969184, 7.91931645491084, 7.61926376889051,
7.9804131283696, 7.84841940402634, 8.17523084115879, 8.20048296800237,
8.15037889614863, 8.49192165017997, 8.12639342202955, 8), val3 = c(8.9935262047237,
9.14278022237807, 9.03679932091872, 8.71124810040193, 8.76215333422409,
8.37943378478808, 8.49591400485852, 8.17523084115879, 8.20048296800237,
8.15037889614863, 8.49192165017997, 8.12639342202955, 8)), row.names = c(NA,
-13L), class = c("tbl_df", "tbl", "data.frame"))
quarters = data %>%
select(Quarter) %>%
pull()
xform <- list(categoryorder = "array",
categoryarray = quarters)
fig <- plot_ly(data,
x = ~Quarter,
y = ~val1,
name = 'val1',
type = 'scatter',
mode = 'lines',
line = list(dash = 'dot',
width = 5))%>%
layout(xaxis = xform)
ay <- list(
tick0 = 0,
dtick = 20,
overlaying = "y",
side = "right",
title = "val2",
showgrid = FALSE)
fig = fig %>%
add_trace(y = ~val2,
name = ' val2',
yaxis = 'y2',
line = list(color = "rgb(122, 157, 07)",
width = 5,
dash = 'line')) %>%
add_trace(y = ~val3,
name = 'val3',
yaxis = 'y2',
line = list(color = "red",
width = 5,
dash = 'line')) %>%
layout(
title = list(text = "values"),
yaxis2 = ay,
xaxis = list(title=" ",
tickmode = "array",
tickvals = sort(c(0, seq( length(quarters)-1,1, -4))),
tickangle = 270,
showgrid = FALSE),
yaxis = list(title="val1")
)
fig


