Aspect ratio with small multiples / subplots
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
I would like to create small multiples with a fixed aspect ratio. However, there seems to be a but somewhere and only some plots retain the correct aspect ratio.
From what I gathered, setting a fixed aspect ratio with plotly is done as follows: layout(yaxis = list(scaleanchor = "x"))
Consider the follwing example:
df <- data_frame(
x = rep(1:5,25),
y = rep(1:5,25),
g = sort(rep(1:25,5))
)
plots <- df %>%
split(.$g) %>%
map(function(x){
plot_ly(data = x, x = ~x, y = ~y, type = "scatter",mode = "lines") %>% add_lines()
})
small_mulitples <- subplot(plots,nrows = 5) %>%
layout(yaxis = list(scaleanchor = "x")) %>%
hide_legend()
If I plot small_mulitples, only the first plot (row 1, column 1) has an aspect ratio of 1. The other have an arbitrary aspect ratio.

Here's the link to the interactive version of this plot: https://plot.ly/~rata_zhaw/1/
Interestingly, if I choose the option shareX = T in subplot(), the entire first column has the correct aspect ratio. Nothing changes if I choose shareY = T
small_mulitples <- subplot(plots,nrows = 5, shareX = T) %>%
layout(yaxis = list(scaleanchor = "x")) %>%
hide_legend()

And here's the link to the interactive version of the second plot: https://plot.ly/~rata_zhaw/3/
If I plot any of the plots individually, the aspect ratio is correct:
plots[[10]] %>%
layout(yaxis = list(scaleanchor = "x")) %>%
hide_legend()
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用 subplot()、nrows = 5 和 layout(yaxis = list(scaleanchor = "x")) 重现所提供的 R 示例;将其与 shareX = T 和单图的情况进行比较。跟踪 subplot() 如何组合各个图的布局,并在每个 small multiple 都能保持固定纵横比而无需共享坐标轴时,认为该 issue 已完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- plotly, r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100