plotly / plotly/plotly.R

Aspect ratio with small multiples / subplots

Open
#1,288 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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.
small_multiples

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()

small_multiples2

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()

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 by reproducing the supplied R example with subplot(), nrows = 5, and layout(yaxis = list(scaleanchor = "x")); compare it with the shareX = T and single-plot cases. Trace how subplot() combines the plot layouts, and consider the issue done when every small multiple retains the fixed aspect ratio without requiring shared axes.

Written by the indexing model from the issue text.

Assessment

Tech stack
plotly, r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.