Panels are different sizes when converting ggplot plot with facets
未关闭
还没有人认领这个 Issue。
bug
ggplotly
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
When converting a ggplot plot with facets to a plotly object the panels are different sizes. Margins are not subtracted from top and bottom rows so these panels end up being taller. This makes it hard to compare among panels. Margins for top and bottom of panels are equal so longer x-axis labels result in large margins on tops of panels with large spacing between panels and a low data-ink ratio.
library(dplyr)
library(ggplot2)
library(plotly)
library(reshape2)
p <- ggplot(data = tips,
aes(x = sex, y = total_bill)) +
geom_jitter(width = 0.1, height = 0) +
facet_wrap(day ~ time, scales = "free_x", ncol = 2) +
theme(axis.text.x = element_text(angle = 45),
strip.text.x = element_text(size = 8,
margin = margin(t = 1, r = 0, b = 1, l = 0, unit = "pt")))
q <- ggplotly(p) %>%
plotly::layout(margin = list(l = 80, r = 0, t = 100, b = 100, pad = 0))
d <- rbind(q$x$layout$yaxis4$domain, q$x$layout$yaxis3$domain, q$x$layout$yaxis2$domain, q$x$layout$yaxis$domain)
df <- data_frame(lb = d[,1], ub = d[,2]) %>%
mutate(range = ub - lb,
panelSpacing = lb - lag(ub))
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用提供的 ggplotly() 示例重现该问题,并检查在 d 中收集的 y 轴域值。首先跟踪 facet 面板和布局边距是如何转换的,然后验证顶部和底部面板的大小相等,并确认间距反映了配置的边距。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100