Data gets dropped in add_trace and consequently points have the wrong color if NA is present
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- r
- Domain
- data-visualization
Research direction
Run the supplied R example through plotly::add_trace and compare its marker colors with the data.frame example. Trace how add_trace handles NA values in x and aligns the marker color vector, then add regression coverage showing that non-NA points retain their corresponding colors.
Written by the indexing model from the issue text.
Description
Have a look at the following code:
library(plotly)
x = c(NA, 2, 3, 4, 5)
color = c(0, 0, 0.5, 1, 1)
# If you try to plot it this way, you get mismatched colors. The NA seems to have been silently dropped and then the wrong indices aligned. The colors of points 2 and 3 are now blue, of 4 is purple and of 5 is green.
plotly::plot_ly()|>
plotly::add_trace(
type = "scatter",
mode = "markers",
x = x,
y = 0,
marker = list(
color = color,
cmin = 0,
cmax = 1,
colorscale = list(list(0, "blue"), list(0.5, "purple"), list(1, "green"))
)
) |>
plotly::layout(
showlegend = FALSE
) |>
plotly::hide_colorbar()
It produces a plot with wrong colors:
I think this is unacceptable behavior, especially since this is not what happens if you do it in the what I consider the classical way:
data.frame(x=x, color=color) |>
plot_ly(x=~x, color=~color, y=0, colors = c("blue", "purple", "green")) |>
hide_colorbar()
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from plotly/plotly.R
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
save_image Error Open
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
Similar issues
-
documentation pkg infrastructure
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
epiverse-trace/epiparameter#511 ·
-
function:write_dwc
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Urgent request: Due to vulnerabilities move to API version 12.6.1 (12.6.2 eventually) or 13.1.1 Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
jbkunst/highcharter#849 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100