Custom dimensions for a ggplot2 boxplot doesn't work with ggplotly
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
When I create a ggplot2 boxplot with custom dimensions (see the bottom of http://ggplot2.tidyverse.org/reference/geom_boxplot.html#examples), plotly doesn't render the boxplot when I apply ggplotly. However, it works ok with a traditional boxplot where the dimensions are calculated by geom_boxplot/stat_boxplot.
Below is a reproducible example of the issue.
## Libraries
library(ggplot2)
library(plotly)
## Using fake data with extreme values
fake_data = data.frame(
y1 = c(rnorm(100, 2, 3), rnorm(10, 10, 15))
)
# ggplot2
g1 = ggplot(data=fake_data, aes(x ="cat1", y= y1)) +
#stat_boxplot(geom="errorbar") +
geom_boxplot() +
labs(title="Traditional Boxplot") +
ylim(c(-5, 25))
g1
quants = quantile(fake_data$y1, c(0.05, .25, .5, .75, .95))
q_df = data.frame(t(quants))
names(q_df) = c("y5", "y25", "y50", "y75", "y95")
g2 = ggplot(data=q_df, aes(x ="cat1")) +
#stat_boxplot(geom="errorbar") +
geom_boxplot(stat="identity", aes(,
ymin = y5, lower = y25,
middle = y50, upper = y75,
ymax = y95)) +
geom_point(data=subset(fake_data, (y1 > q_df$y95) | (y1 < q_df$y5)), aes(y=y1)) +
labs(title="5%/95% Boxplot") +
ylim(c(-5, 25))
g2
# plotly
plotly::ggplotly(g1)
plotly::ggplotly(g2) # DOESN'T WORK!
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 and compare ggplotly(g1) with ggplotly(g2), focusing on the stat="identity" boxplot and custom ymin, lower, middle, upper, and ymax mappings. Reproduce the failure, then trace the ggplotly conversion path for these boxplot values; done means the custom-dimension plot renders while preserving the outlier points.
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