plotly / plotly/plotly.R

Color group does not appear in the animated plotly

未关闭
#1,805 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

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')

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行提供的用于动画散点图和箱线图的 R 示例,然后比较各年份帧之间的类别图例和 traces。当 type3 从一开始就得到一致处理,并且散点图具有预期的颜色和图例行为、箱线图具有定义明确的空白或延迟出现状态时,该 issue 即得到解决。

由索引模型根据 Issue 内容生成。

评估

技术栈
plotly, r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。