ggplotly() is unable to merge legend entries across layers
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
Thanks for an amazing package! The mapping between plotly and ggplot is particularly impressive and very powerful!
However, ggplotly fails to reproduce the appropriate legends generated by ggplot in non-trivial facet_wrap cases. After discussion on stackoverflow some of this behavior appears to be a bug.
Consider the following minimal reprex:
library(plotly)
library(ggplot2)
p <- mpg %>%
ggplot(aes(year)) +
geom_ribbon(aes(ymin=cty, ymax=hwy, fill = manufacturer), alpha=0.2) +
geom_line(aes(y = hwy, col=manufacturer)) +
facet_wrap(~class)
p
plotly::ggplotly(p)
Note that (a) we get too many plotly legend entries, duplicating the legend for each facet, due to legendgroup not being correctly handled. Also note (b) the legends we do and don't get depend on the order (do we do geom_ribbon first or geom_line first). The bug does not appear if we have only one geom, and the missing legends continue as we add more geoms.
Perhaps not related -- but the interactive zoom options in faceted plots are not entirely intuitive either, i.e. it's not possible to zoom the whole window on a single facet plot. (Perhaps the take home is that it might be better to render facet plots as more independent objects in plotly)?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从使用 geom_ribbon、geom_line 和 facet_wrap(~class) 的最小 ggplotly() reprex 开始,然后检查 legendgroup 在各图层和分面之间的处理方式。将转换后的图例与 ggplot2 预期的图例进行比较;无论 geom 的顺序如何,都没有重复或缺失的条目,同时保留分面行为,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100