How to fill between lines with plotly when missing data is present?

Viewed 41

Consider the following code

set.seed(1234)
r = rnorm(200)
ir = cumsum(r)
df = data.frame(low = ir - 2*abs(r), high = ir + 2*abs(r), mid = ir, x = 1:200)
df[90:110,] <- NA

plot_ly(data = df) |>
  add_lines(x = ~x, y = ~high, line = list(width = 2), name = "high") |>
  add_lines(x = ~x, y = ~low, fillcolor='rgba(0,100,80,0.2)', fill = "tonexty", line = list(width = 2), name = "low") |>
  add_lines(x = ~x, y = ~mid, line = list(color = "black"), name = "mid")

which generates the following chart

enter image description here

I want to have a break in the chart where the data is missing, and I want to fill the area between the lines, but I don't want this weird artifact you can see. Any ideas?

0 Answers
Related