plotly / plotly/plotly.R

For a categorical colour aesthetic, there appears to be no documented way to use selectedpoints to select individual points.

Open
#2,459 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

The following example highlights the first point from each colour group (the first "a" point and the first "b" point):

library(plotly)

d <- data.frame(x = 1:4, c = c("a", "a", "b", "b"))

plot_ly(d) |>
  add_trace(x=~x, y = ~x, color = ~c, type = "scatter", selectedpoints = list(0))

From the plot_ly() documentation, it appears that this code implicitly creates multiple traces, one for each colour, so this behaviour makes sense on this level (even if it's surprising). However, there appears to be no documented way to access individual traces. I've tried a number of permutations

In my opinion, if the code is going to transparently create multiple traces like that, it should also transparently map selectedpoints provided by the user (ideally as 1-based indexes or logical vectors, for consistency with R) to their positions within each trace.

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 with the plot_ly() documentation and the categorical-colour example to trace how colour creates separate traces and how selectedpoints is passed through. Done means providing a documented, consistent way to select points within each generated trace, with coverage for the shown example and the proposed R-style indexing behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.