legendrank (bar chart example)
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
This bug report concerns R plotly 4.10.1.
I was going to file a report regarding a more complex composite chart; involving bars and lines; as I noticed when there was an NA(or NaN) value to plot against the Y axis , the legend orders got scrambled. I was able to directly address this shortcoming in my own code by na.omit() on my input dataset. However , in the course of trying to simplify my code down to be more minimal for this reprex, I encountered a more basic issue of the legendrank seemingly not being respected
library(tidyverse)
library(plotly)
(tot_df <- structure(list(
rank = structure(c(
1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L
), levels = c(
"1", "2", "3",
"4"
), class = "factor"), value = c(
1, 0.316227766016838, 2, 0.447213595499958,
3, 0.547722557505166, 4, 0.632455532033676, 5, 0.707106781186548,
3, 0.547722557505166, 2, 0.447213595499958, 1, 0.316227766016838
), name = c(
"stat1", "stat_2", "stat1", "stat_2", "stat1", "stat_2",
"stat1", "stat_2", "stat1", "stat_2", "stat1", "stat_2", "stat1",
"stat_2", "stat1", "stat_2"
), `Display name` = structure(c(
1L,
1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L
), levels = c(
"Reference",
"Current"
), class = "factor"), series_name_text = structure(c(
1L,
2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L
), levels = c(
"Reference stat1",
"Reference stat_2", "Current stat1", "Current stat_2"
), class = "factor"),
my_legend_rank = c(
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L
)
), row.names = c(NA, -16L), class = c(
"tbl_df",
"tbl", "data.frame"
))
)
px <- plot_ly(
data = tot_df,
width = 800,
height = 600,
x = ~rank,
y = ~value,
name = ~series_name_text,
legendrank = ~my_legend_rank,
color = ~`Display name`,
colors = c("green", "blue"),
textposition = "none",
type = "bar",
opacity = .5,
yaxis = "y"
) |> layout(legend = list(
orientation = "h",
xanchor = "center",
yanchor = "bottom",
y = -0.3,
x = 0.5
))
# table(tot_df$series_name_text,tot_df$my_legend_rank
# 1 2 3 4
# Reference stat1 4 0 0 0
# Reference stat_2 0 4 0 0
# Current stat1 0 0 4 0
# Current stat_2 0 0 0 4
plotly_json(px)

It seems to me that based on legendrank 'Reference stat1 should be the first i.e. leftmost trace name observed within the legend box, and this isnt the case, the first seen is Current stat1, that should be in 3rd position...)
Is there a gotcha here ? some incorrect setup ? something that invalidates the use of legendrank ?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
运行提供的 R reprex 并检查 plotly_json(px),重点关注条形 trace 的 legendrank 映射是如何表示的。将生成的图例顺序与请求的 rank 进行比较;完成意味着 trace 要么按 rank 顺序显示,要么该 issue 得到解释并由适当的回归测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- plotly, r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100