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

Aperta
#848 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

ggplotly
Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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!

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il problema utilizzando gli esempi ggplot2 e plotly in R presenti nel report, confrontando la conversione ggplotly con il grafico plot_ly equivalente e con il layout orizzontale della legenda. Traccia il comportamento della conversione e del rendering per identificare il motivo per cui la legenda ggplotly viene troncata, quindi verifica che le legende lunghe vengano visualizzate su più righe senza alterare il comportamento del grafico riportato nel report.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
r
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.