plotly / plotly/plotly.R

Categoryorder not working when specifying plot type

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

还没有人认领这个 Issue。

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

描述

When using the category order parameter, no plot is generated if the plot type is specified in the plot_ly call:

p <- plotly::plot_ly(type = 'bar')
colNames <- names(iris)
colNames <- colNames[-which(colNames == 'Species')]

for(trace in colNames){
  p <- p %>% plotly::add_trace(data= iris, x = ~ Species, y = as.formula(paste0("~`", trace, "`")), name = trace)
}

p  %>% layout(xaxis = list(categoryorder='total descending'))

With the following warning, which I don't understand since I'm not combining discrete and non-discrete data in the same axis:

Warning message:
Can't display both discrete & non-discrete data on same axis 

If I specify the type in add_trace instead of the plot, then it works correctly and the warning is gone:

p <- plotly::plot_ly()
colNames <- names(df)
colNames <- colNames[-which(colNames == 'Species')]

for(trace in colNames){
  p <- p %>% plotly::add_trace(type = 'bar', data= iris, x = ~ Species, y = as.formula(paste0("~`", trace, "`")), name = trace)
}

p %>% layout(xaxis = list(categoryorder='total descending'))

Maybe this is the intended behavior? If so, why does specifying the type in the traces works and not in the plot? The warning seems unclear to me.

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先使用 iris 运行提供的 R reproduction,并比较 plot_ly(type = 'bar') 与 add_trace(type = 'bar')。跟踪 plot_ly 和 add_trace 如何传递 type,以及 layout(xaxis = list(categoryorder = 'total descending')) 如何处理生成的 traces。完成的标准是 reproduction 不再发出警告,并且 category 排序始终一致。

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

评估

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

把新 issue 发到你的邮箱

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