plotly / plotly/plotly.R

Long legend with horizontal orientation got truncated when converting ggplot object using ggplotly but it's fine when using plot_ly

Abierto
#848 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

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

Descripción

Hi all, as a work-around approah to display a very long multi-column legend, I tried to use the layout(legend = list(orientation = "h")).

Here is the data_frame I was working with:
image

When I first built a ggplot object and then used ggplotly to convert it, I got this:
p <- ggplot(df, aes_string("cluster", "mCH", fill="cluster"))
p <- p + geom_boxplot() + scale_fill_manual(values = colors2, name="Cluster") + theme_bw() + ggtitle("someGene")
p.ggplotly <- p %>% ggplotly(tooltip = c("cluster", "mCH", "density")) %>% layout(legend = list(orientation = "h"))
p.ggplotly

image

The legend had only one row and it just got out of the margin... But when I did a similar thing using plot_ly the legend was fine:

p.plotly <- plot_ly(df,x=~cluster, y=~mCH,type="box", color=~cluster, colors=colors2) %>% layout(legend=list(orientation = "h"))
p.plotly
image

And I thought this is somehow control by the layout, so I tried copying the layout from p.plotly to p.ggplotly:
p.ggplotly.bak <- p.ggplotly
p.ggplotly$x$layout <- p.plotly$x$layout
But the legend was still truncated...
p.ggplotly
image

However if I did it the other way around, I got a something like this:
p.plotly$x$layout <- p.ggplotly.bak$x$layout
p.plotly

image

The legend was displayed correctly with multiple rows(even though the position was not right, but I know how to adjust for that).

I'm not sure if this is because the ggplotly and plot_ly is inherently different, or there're other options that can controll this behavior (or this is just a bug?). Any idea? I somehow prefer to use ggplotly...

FYI, ggplot2 version is 2.2.1 and plotly version is 4.5.6.9000. Thanks!

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

Reproduce el problema utilizando los ejemplos de ggplot2 y plotly en R incluidos en el informe, comparando la conversión de ggplotly con el gráfico plot_ly equivalente y con el diseño horizontal de la leyenda. Rastrea el comportamiento de conversión y renderizado para identificar por qué la leyenda de ggplotly aparece truncada y, después, verifica que las leyendas largas se muestren en varias filas sin alterar el comportamiento del gráfico descrito en el informe.

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

Evaluación

Stack tecnológico
r
Área
data-visualization
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.