Adding 'name' parameter to plot_ly() function removes factor ordering.
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
We sometimes use the 'name' parameter within the plot_ly() function to add a suffix to the values shown in a legend. Values in the legend are shown because a variable (legend variable) is used for the 'color' parameter in plot_ly().
Since a few days/weeks, using this method to add a suffix leads to the ordering of 'legend variable' to switch to alphabetical order instead of its original factor levels.
I added an example below.
library(plotly)
library(lubridate)
factor <- factor(x = c('bbb', 'ccc', 'aaa'), levels = c('bbb', 'ccc', 'aaa'))
number <- c(1,2,3)
date <- c(ymd(20170101), ymd(20170202), ymd(20170303))
levels(factor)
df <- data.frame(letter = factor, number = number, date = date)
levels(df$letter)
plot_ly(df, x = ~number, y = ~date, type = 'bar', color = ~letter)
plot_ly(df, x = ~number, y = ~date, type = 'bar', color = ~letter, name = 'ff')
plot_ly(df, x = ~number, y = ~date, type = 'bar', color = ~letter, name = c('asd', 'ff', 'ss'))
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行使用 plot_ly() 和 color = ~letter 的可复现 R 示例,先不使用 name,然后使用 name 的每种形式。跟踪 plot_ly() 对因子水平和图例名称的处理;完成的标准是,在所有展示的案例中,图例都保留因子顺序 bbb, ccc, aaa。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- plotly, r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100