-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with NA handling in scatter plots: Two NAs per category cause incorrect line connection #2419
Comments
I looked in depth into what is happening, and the generated plotly.js data is genuinely missing the null values. Will need to investigate deeper, looks like a genuine bug in the R code to me at the moment. |
I found the culprit... the function This sounds like very fragile code, I need to think more about how this could be fixed. The culprit is https://github.com/plotly/plotly.R/blob/aa619dc2fbc2fa786e15a8d11444a18863661ed4/R/plotly_build.R#L996C57-L996C71 - this needs to be replaced with a more robust check for "is this entry splittable?" |
If this is not done (or similar), in rare situations the `recurse` function splits the variable list into parts if it happens to match length of the column to split by. Fixes plotly#2419
Issue Summary
When using plot_ly() in R with a scatter plot (mode = "lines+markers"), missing (NA) values are expected to create gaps in the line plot. However, if exactly two NA values exist per category, the missing values are incorrectly connected by a line instead of creating a gap.
Interestingly, when the hovertemplate is removed, the line plot behaves as expected (i.e., creating a gap for NA values). This issue only occurs when there are exactly two NA values per category; the code works with any other number of NA values.
Additional Discovery:
The issue is resolved if I include the argument split = ~Category, but I cannot find documentation for split in Plotly, which makes me think it may be deprecated. Moreover, when the hovertemplate is removed, the inclusion of split does not work as expected and does not resolve the issue.
Reproducible Example
The following R code demonstrates the issue:
Expected Behaviour
Actual Behavior
Additional Notes
This seems to be an issue specifically triggered by the combination of NA handling and the hovertemplate. I would appreciate further insight on why this happens or suggestions for a workaround to preserve the gap in the case of two NA values.
System Info
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows Server 2019 x64 (build 19045)
Matrix products: default
The text was updated successfully, but these errors were encountered: