plotly / plotly/plotly.R

R plotly boxplots overwriting with numerical labels

Ouverte
#2,274 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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

R plotly boxplots overwriting with numerical labels

I've asked this question on SO here: https://stackoverflow.com/questions/76466189/r-plotly-boxplots-overwriting-with-numerical-labels, but I'm wondering if it's a bug with the latest versions of the plotly library in R

Plotting boxplots with numeric (or numeric-as-character) as x-variable results in boxplots a) not located in the correct locations and b) with boxes overplotted

library(plotly)

colors <- c("red","blue","green","pink","brown")
data.in <- data.frame(Age=25*rnorm(100)+50, IMD=sample(5,100,replace=TRUE))
fig <- plot_ly(data=data.in[data.in$IMD == "1",], y=~Age, type="box", color=I(colors[1]),name="1 - least")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "2",], y=~Age, type="box", color=I(colors[2]),name="2")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "3",], y=~Age, type="box", color=I(colors[3]),name="3")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "4",], y=~Age, type="box", color=I(colors[4]),name="4")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "5",], y=~Age, type="box", color=I(colors[5]),name="5 - most")
fig <- fig %>% layout(yaxis = list(title = "Age"),
                      xaxis = list(title = "IMD"),
                      boxgap = 0.1, boxgroupgap=0)

This results in a plot similar to
Screenshot 2023-06-13 at 15 41 15
Specifying 'x=~' in each add_trace does place the boxes in the correct places so is a temporary workaround, but I think that this may be a bug with the package, as the above code with labels which don't start with numbers (in the 'name=' attribute) does give the correct placement:

library(plotly)

colors <- c("red","blue","green","pink","brown")
data.in <- data.frame(Age=25*rnorm(100)+50, IMD=sample(5,100,replace=TRUE))
fig <- plot_ly(data=data.in[data.in$IMD == "1",], y=~Age, type="box", color=I(colors[1]),name="A")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "2",], y=~Age, type="box", color=I(colors[2]),name="B")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "3",], y=~Age, type="box", color=I(colors[3]),name="C")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "4",], y=~Age, type="box", color=I(colors[4]),name="D")
fig <- fig %>% add_trace(data=data.in[data.in$IMD == "5",], y=~Age, type="box", color=I(colors[5]),name="E")
fig <- fig %>% layout(yaxis = list(title = "Age"),
                      xaxis = list(title = "IMD"),
                      boxgap = 0.1, boxgroupgap=0)
Screenshot 2023-06-13 at 17 39 13

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la reproduction R fournie en utilisant plot_ly(), add_trace() et layout(); comparez les noms de traces numériques et non numériques ainsi que le workaround explicite x=. C’est terminé lorsque les traces de boxplot dont les noms sont numériques ou numériques sous forme de caractères occupent des positions x distinctes et prévues sans nécessiter de valeurs x explicites. Aucun fichier source ni test n’est nommé dans l’issue.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
plotly, r
Domaine
data-visualization
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.