0

Question:

Is it possible to ignore specific traces using plotly in R?

Motivation:

The following gives a motivation based on a previously asked question:

library("plotly")

fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)

hrect <- function(y0 = 0, y1 = 1, fillcolor = "red", opacity = 0.2) {
  list(
    type = "rect",
    x0 = 0,
    x1 = 1,
    xref = "paper",
    y0 = y0,
    y1 = y1,
    line_width = 0,
    fillcolor = fillcolor,
    opacity = opacity,
    layer = "below"
  )
}

Y_RANGE = 1000
fig <- fig  |> plotly::layout(shapes = list(
  hrect(y0 = Y_RANGE*-1, y1 = 3, fillcolor = "red"),
  hrect(y0 = 3, y1 = 6, fillcolor = "blue"),
  hrect(y0 = 6,  y1 = Y_RANGE, fillcolor = "green")),
  yaxis = list(range = c(0, 8))
)

fig

The problem is that autoscale scales to the background rectangles and even more problematic it permanently modifies the aspect ratio of the figure:

enter image description here

Remark:

Not sure if asking the same question using R and not Python really qualifies for asking a new question, so here is the link to the same question using Python.

moremo
  • 315
  • 2
  • 11

0 Answers0