plotly.R
plotly.R copied to clipboard
layout.shapes.legendgroup is unexpectedly non-functional
layout.shapes.legendgroup is non-functional although included in the official reference (https://plotly.com/r/reference/layout/shapes/)
In the below reprex, I have set all objects to the same legendgroup. I would expect them all to disappear when clicking on the legend but this does not happen.
library(plotly)
x <- seq(-2 * pi, 2 * pi, length.out = 1000)
df <- data.frame(x, y1 = sin(x), y2 = cos(x))
fig <-
plot_ly(df, x = ~x) %>%
add_lines(y = ~y1, name = "A", legendgroup = "B") %>%
add_lines(y = ~y2, name = "B", legendgroup = "B")
fig %>%
plotly::layout(shapes =
list(
list(type = "rect",
fillcolor = "blue", line = list(color = "blue"), opacity = 0.3,
x0 = -1, x1 = 1, xref = "x",
y0 = -0.5, y1 = 0.5, yref = "y", legendgroup = "B")))
Example adapted from https://plotly.com/r/dropdowns/