partial bar highlight does not work on `geom_bar()` or `geom_hist()` converted with `ggplotly()`
未关闭
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
A highlighted plotly "histogram" can have its bars partially highlighted (with best results achieved with the "overlay" barmode), but an equivalent ggplot2 object converted with ggplotly() can't.
This reproducible example showcases all three options. One can drag a rectangle around some points to see that only the pure plotly visualisation gets bar overlays. A bar will only be completely highlighted if all the cases for that bar are selected in the scatterplot.
library(ggplot2)
library(plotly)
# set up highlightable dataset
msleep_h <- highlight_key(msleep)
# scatterplot
gg_point <- (ggplot(msleep_h, aes(x = sleep_total, y = sleep_rem)) +
geom_point()) %>%
ggplotly()
# ggplot2 bar chart does a count
gg_bar <- (ggplot(msleep_h, aes(x = conservation)) +
geom_bar()) %>%
ggplotly() %>%
layout(barmode = "overlay")
# also try a histogram geom, which requires switching to the count stat
gg_hist <- (ggplot(msleep_h, aes(x = conservation)) +
geom_histogram(stat = "count")) %>%
ggplotly() %>%
layout(barmode = "overlay")
# plotly equivalent
plt_hist <- plot_ly(msleep_h) %>%
add_histogram(x = ~conservation) %>%
layout(barmode = "overlay")
# side by side
subplot(gg_point, gg_bar, gg_hist, plt_hist) %>%
highlight("plotly_selected")

贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中可复现的 R 示例开始,重点关注 geom_bar() 和 geom_histogram(stat = "count") 的 ggplotly() 转换,以及最后的 highlight("plotly_selected") 调用。将它们的选择行为与使用 barmode = "overlay" 的纯 plotly 直方图进行比较;完成的标准是,选择柱状条的一部分时,在两个转换后的图中都只叠加所选案例。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100