I would like to add to the hover information about the difference between the values in the chart. It would be best if it looks like the graphics below.
My example:
library(plotly)
trace_1 <- sample(1:20)
main <- sample(1:20)
diff <-main - trace_1
x <- c(1:20)
data <- data.frame(x, trace_1, diff)
fig <- plot_ly(data, x = ~x, y = ~trace_1, name = 'trace 1', type = 'scatter', mode = 'lines')
fig <- fig %>% add_trace(y = ~main, name = 'main', type = 'scatter', mode = 'lines')
fig <- fig %>%
layout(hovermode = "x unified")
fig