Issue when specifying both the size and color mapping in a scatter plots
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I can not manage to specify both the size and the color mapping with completely satisfactory results.
If I specify the size mapping globally:
library(plotly)
df <- data.frame(x = 1:12, y = 1:12, s = 1:12, g = rep(c("A", "B", "C"), 4))
plot_ly(data = df, x = ~x, y = ~y, size = ~s, color= ~g)%>%
add_markers()
I have a perfect plot but I suffer from the spurious line.width warning already mentioned in https://github.com/ropensci/plotly/issues/1367
If I specify the size mapping in the marker itself:
plot_ly(data = df, x = ~x, y = ~y, color= ~g)%>%
add_markers(marker = list(size = ~s))
The sizes are wrong: it seems there is an ordering by group within plotly which is not used in the markers.
Indeed, sorting the data.frame according to the colors fixes the issue:
df_sorted = df[order(df[['g']]), ]
plot_ly(data = df_sorted, x = ~x, y = ~y, color= ~g)%>%
add_markers(marker = list(size = ~s))
Let me know how I can help!
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.
Research direction
Start with the two unsorted examples using plot_ly() and add_markers(), then compare their marker-size behavior with the sorted data.frame example. Trace how color grouping and marker size mappings are aligned, and verify that unsorted data preserves the intended sizes without the reported line.width warning.
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
- 35/100