plotly / plotly/plotly.R

Aspect ratio with small multiples / subplots

Abierto
#1,288 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement
Lenguaje dominante
R
Estrellas
2.7k
Forks
641
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza reproduciendo el ejemplo de R proporcionado con subplot(), nrows = 5 y layout(yaxis = list(scaleanchor = "x")); compáralo con los casos shareX = T y de un único gráfico. Rastrea cómo subplot() combina los layouts de los gráficos y considera resuelto el problema cuando cada small multiple conserve la relación de aspecto fija sin requerir ejes compartidos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
plotly, r
Área
data-visualization
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.