partial bar highlight does not work on `geom_bar()` or `geom_hist()` converted with `ggplotly()`
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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")

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible R example in the issue, especially the ggplotly() conversions of geom_bar() and geom_histogram(stat = "count") and the final highlight("plotly_selected") call. Compare their selection behavior with the pure plotly histogram using barmode = "overlay"; done means selecting part of a bar overlays only the selected cases in both converted plots.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100