Issues with legend position, in particular since update 4.10
Personne n'a encore pris cette issue.
- Langage dominant
- R
- Étoiles
- 2.7k
- Forks
- 641
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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?
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par exécuter le reproducteur R fourni avec plotly 4.9.4.1 et 4.10, puis comparez le retour à la ligne de la légende, la taille des barres et le positionnement pour des largeurs proches. Le travail est considéré comme terminé lorsque la régression est expliquée ou corrigée, et que le positionnement de la légende ainsi que le comportement de la largeur ont été vérifiés par rapport aux exemples signalés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- r
- Domaine
- data-visualization
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100