plotly / plotly/plotly.R

layout.shapes.legendgroup is unexpectedly non-functional

Open
#2,290 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

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/

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided R reprex and compare the shape's legendgroup behavior with the two line traces. Use the layout.shapes reference as the expected behavior; done means clicking the shared legend entry hides and shows the shape together with the grouped traces.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.