plotly / plotly/plotly.R

ggplotly() unable to fit 4 plots in 3 columns using a "ggplot() + facet_wrap()" object

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

还没有人认领这个 Issue。

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

描述

Hi,
It turns out that ggplotly() is unable to fit 4 plots in 3columns when the ggplot object to be converted was designed using this structure ggplot(df, aes(x,y) + facet_wrap(~ var, ncol = 3). It does not matter which example you use.

Let's use this example from the plotly community website, see section "labels":

https://plotly.com/ggplot2/facet_wrap/#labels

df <- diamonds[sample(1:nrow(diamonds), size = 1000), ]

# Create labels
labs <- c("Best","Second best","Third best","Average", "Average","Third Worst","Second Worst","Worst")
levels(df$clarity) <- rev(labs)

# filter variable "clarity" to get 4 plots in the facet
df <- df %>% 
       filter(clarity %in% c("Worst", "Average", "Third best", "Best"))

p <- ggplot(df, aes(carat, price)) + 
    geom_point() + 
    facet_wrap(~ clarity, ncol = 3) # make clear that 3 columns are needed

fig <- ggplotly(p)

fig

I will attach the outputs so you can see the bug:
newplot (6)
newplot (7)
newplot (8)
newplot (9)

It is easy tu bypass this issue, just changing the number of columns. Nevertheless, it would be great if this didn't happen.

Kind regards,

Sergi

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用 Plotly 的“facet_wrap labels”页面中的 diamonds 示例,使用 ggplot() 配合 facet_wrap(~ clarity, ncol = 3),并通过 ggplotly() 进行转换,以重现该问题。检查 facet_wrap 转换,并将渲染结果与原始 ggplot 进行比较。当转换后的图形中四个图表能正确地排布在三列中时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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