plotly / plotly/plotly.R

Custom dimensions for a ggplot2 boxplot doesn't work with ggplotly

未关闭
#1,098 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug ggplotly
主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

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!

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中可复现的 R 示例开始,比较 ggplotly(g1) 和 ggplotly(g2),重点关注使用 stat="identity" 的箱线图以及 ymin、lower、middle、upper 和 ymax 的自定义映射。复现该故障,然后跟踪这些箱线图值的 ggplotly 转换路径;当自定义维度的图表在保留离群点的同时完成渲染时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。