Color group does not appear in the animated plotly
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to plot an animated frame with plotly. The goal is to plot how some units (id) changes in two continuous variables AND one categorical. The problem arises because the third category appears not from the beginning. In the plot, the units with “type3” category do not appear on the plot after 2001 and the ‘type3’ entry does not appear in the legend. The code shows an example of the data structure and problem. The same problem with boxplot - only two categories are present for all frames.
The ideal result is appearing of all 3 groups form the beginning. For scatterplot, points should change the color and for boxplot there should be an empty space from the beginning for the third category or it should appear after reaching the proper year.
df <- data.frame(x = rnorm(50),
y = rnorm(50),
year = c(rep(2000, 10), rep(2001, 10), rep(2002, 10), rep(2003, 10), rep(2004, 10)),
id = rep(1:10, 5),
model = c(rep('type1', 5), rep('type2', 5), rep('type1', 5) , rep('type2', 5),
rep('type1', 3), rep('type2', 2), rep('type3', 5) ,
rep('type1', 4), rep('type2', 5), rep('type3', 1) ,
rep('type1', 3), rep('type2', 2), rep('type3', 5) ))
cols <- c(
"type1" = "#bc80bd",
"type2" = "#fdb462",
"type3" = "#b3de69"
)
plot_ly(df, x = ~x,
y= ~y,
color = ~model,
text = ~id,
frame = ~year,
opacity = .8,
marker = list(size = 10),
colors = cols,
type = 'scatter')
plot_ly(df,
y= ~y,
color = ~model,
frame = ~year,
opacity = .8,
colors = cols,
type = 'box')
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 supplied R examples for animated scatter and box plots, then compare the category legend and traces across the year frames. The issue is resolved when type3 is handled consistently from the beginning, with the expected color and legend behavior for scatter plots and a defined empty-or-late appearance for box plots.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100