Bubble changing color and representing a different category in animated scatter plot
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
I was trying to create an animated scatter plot with each bubble representing a race category indicated by a color. In the actual data set, some race categories don't data in certain years. When those years were excluded, the plot looked fine. However, when those years were not excluded, some bubbles changed colors and turned into a different race category . For example, in the code below, race 4 changed into race 5 in year 6 when race 4 actually does not have data in year 6 - year 9. Thanks!
str <-
"seq, race, achievement, growth, size
year 1, race 6, 41.5, 35.5, 54
year 2, race 6, 45.5, 48.5, 54
year 3, race 6, 37.0, 34.5, 64
year 4, race 6, 42.0, 29.5, 62
year 5, race 6, 39.0, 40.0, 60
year 6, race 6, 39.0, 41.0, 71
year 7, race 6, 33.0, 40.0, 74
year 8, race 6, 25.0, 42.0, 59
year 9, race 6, 24.0, 55.0, 59
year 1, race 2, 22.0, 36.0, 357
year 2, race 2, 23.0, 43.0, 357
year 3, race 2, 21.0, 42.0, 359
year 4, race 2, 18.0, 45.0, 364
year 5, race 2, 21.0, 42.0, 351
year 6, race 2, 20.0, 54.0, 353
year 7, race 2, 17.0, 41.0, 370
year 8, race 2, 13.0, 46.0, 319
year 9, race 2, 14.0, 48.0, 318
year 1, race 3, 39.0, 47.0, 2
year 2, race 3, 29.5, 28.5, 2
year 3, race 3, 36.0, 29.5, 2
year 4, race 3, 34.5, 64.5, 2
year 5, race 3, 35.5, 70.5, 2
year 6, race 3, 69.0, 35.0, 1
year 7, race 3, 60.0, 21.0, 1
year 1, race 5, 65.0, 59.0, 23
year 2, race 5, 68.0, 44.0, 23
year 3, race 5, 54.0, 57.0, 17
year 4, race 5, 49.0, 43.0, 19
year 5, race 5, 45.5, 49.0, 20
year 6, race 5, 54.0, 64.0, 23
year 7, race 5, 48.0, 56.0, 32
year 8, race 5, 37.0, 68.0, 35
year 9, race 5, 37.0, 58.0, 37
year 1, race 7, 35.0, 46.0, 99
year 2, race 7, 40.0, 57.5, 100
year 3, race 7, 37.0, 40.0, 113
year 4, race 7, 36.0, 51.5, 110
year 5, race 7, 33.0, 41.0, 108
year 6, race 7, 39.0, 53.0, 101
year 7, race 7, 30.0, 40.0, 106
year 8, race 7, 28.0, 53.0, 111
year 9, race 7, 28.0, 53.0, 106
year 1, race 4, 74.5, 93.0, 2
year 2, race 4, 69.5, 80.5, 2
year 3, race 4, 84.0, 98.0, 1
year 4, race 4, 82.0, 44.0, 1
year 5, race 4, 60.0, 3.0, 1
year 1, race 1, 47.0, 38.0, 461
year 2, race 1, 48.0, 42.5, 454
year 3, race 1, 49.0, 41.0, 449
year 4, race 1, 48.0, 52.0, 461
year 5, race 1, 47.0, 42.0, 448
year 6, race 1, 52.0, 47.0, 412
year 7, race 1, 47.0, 39.0, 416
year 8, race 1, 38.0, 46.5, 362
year 9, race 1, 41.0, 51.0, 362"
dt <- read.table(textConnection(str), header=T, sep=",", na.strings=" ")
plot_ly(dt) %>%
add_markers(x = ~achievement, y = ~growth, size = ~size,
color = ~race,
frame = ~seq,
hoverinfo = 'text', text = ~paste(race, size, sep = '\n'),
marker = list(opacity = 0.5, sizemode = 'diameter'))
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 by running the reproducible R example from the issue with plotly.R and compare the animated frames where race 4 has no data. Trace how frame values are matched to marker colors. Done means each race keeps its assigned color when categories are missing in later years.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100