Issues with legend position, in particular since update 4.10
Nessuno ha ancora preso questa issue.
- Lingua principale
- R
- Stelle
- 2.7k
- Fork
- 641
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Hey,
it's been a while I am struggling with the position of the legend in plotly. First, let me report a small bug, then I'll ask another question.
Reprex: execute the following code with plotly 4.9.4.1 and 4.10, respectively. You'll see that the legend holds on one line in 4.9.4.1 vs. two lines in 4.10 (cf. figures below).
bars <- plot_ly(x = .5, y = "foo", type = 'bar', orientation = 'h', name="First color of legend") %>% # , marker = list(color = 'red', line = list(color = 'white')
layout(barmode = 'stack', margin = list(t = 50), showlegend = T,
legend = list(orientation='h', y=1.2, x=0.2, traceorder='normal', font=list(size=12, color='black'))) %>%
add_trace(x = .5, name="Second color of legend")
bars
orca(bars, width = 415, height = 150, file = "temp.png")
4.9.4.1

4.10

I had optimized hundreds of images with the old version, so I'll just keep the old version running, to avoid having to manually adjust hundreds of width parameters. It may seem an innocuous change for people who start creating their figures with the last version (4.10). But actually it forces to create wider figures if one wants to keep the legend in one line. This in turn widens the relative size of the bar to the detriment of the label (foo), thus rendering the label text smaller (and less readable) when one embeds this figure in a document (with width constrained to text width). Also, notice a related bug: for some widths values close to the switch between one line and two lines legend, the size of the bar reduces for no reason. This offsets the legend from the bar and ends up in an ugly plot.
I could solve my bug by using the old package, so I don't really mind. But as I am here, I'd like to know if there is some way to automatize the positioning of the legend and the width of the figures.
My issue is that I am creating hundreds of figures to plot survey results, variable by variable (see e.g. here). I have created a semi-automatized function that takes to plot a variable in a bar chart like the one above, but I still need to find manually the minimum width such that the legend holds in one line (and doesn't mask the bar), which is quite cumbersome. Another thing that I'd like to automatize is the placement of the legend: I'd like it to be the furthest possible to the left (again, to minimize width), and this depends on the size of the labels.
Are there ways to automatize the placement of the legend's "x" as well as the width with which to save the graph? Or more generally, is there a function to nicely plot a factor variable in a bar chart, by just giving the variable and the function automatically adjusts the parameters to make a nice plot?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il riproduttore R fornito con plotly 4.9.4.1 e 4.10, quindi confronta l'andata a capo della legenda, la dimensione delle barre e il posizionamento a larghezze vicine. Il lavoro è completato quando la regressione è stata spiegata o corretta e il posizionamento della legenda e il comportamento della larghezza sono stati verificati rispetto agli esempi segnalati.
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
- Abbastanza chiara
- Idoneità per principianti
- 25/100