plotly / plotly/plotly.R

plotly::subplot with >= 3 rows/cols results in different sized plots for inner/boundary plots

Open
#2,057 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

As per title, when making a subplot with >= 3 rows or columns with a margin (default is 0.02 but the issue is easier to see with more plots/bigger margins)

library(magrittr)
p <- plotly::plot_ly(mtcars, x = ~cyl, y = ~mpg, color = ~rownames(.data), type = "bar") %>% plotly::layout(showlegend = FALSE)
plotly::subplot(p, p, p, p, p, p, p, p, p, nrows = 3, margin = 0.1)

image

There is a PR (#622) which aims to fix it, but the PR also does some extra things like make the margins fixed rather than scaled. I think it's possible to provide a much quicker & simpler fix as an alternative, given that this has been known about since 2016.

I think in a nutshell its due to the function get_domains & it's for loops:
https://github.com/plotly/plotly.R/blob/4bb1e44c5e27898bdf7ac45422564fa5200fb5f5/R/subplots.R#L385-L401
It's those if's that are the problem, can they be removed without causing too much trouble?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with R/subplots.R, especially get_domains and the loops around lines 385–401. Run the supplied R example with nrows = 3 and margin = 0.1, then compare the domain sizing for inner and boundary plots. Done means subplot panels have consistent sizes; review PR #622 for related work before proceeding.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.