plotly / plotly/plotly.R

ggplotly with points, error bars and facets error

Ouverte
#1,710 2 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

I am building a ggplot which has points, error bars and facets. I use the ggplotly() function to create a plotly graph, but I get the error returned below. With a bit of tracing back, I found the error to be in ggplotly() -> layers2traces() -> to_basic() when it's applied to the error bar geometry (it works when applied to the points geometry). In particular, it crashes on this line

data$width <- (data[["xmax"]] - data[["x"]])/(data[["x_max"]] - 
                                                data[["x_min"]])

Because x is not an element in data. In a slightly larger case than the reprex below, but with the same properties, I found the following when applying head() to the data object in the browser:

Browse[4]> head(data)
PANEL  colour   x.x         y      ymin      ymax group x_plotlyDomain
1     1 #00BFC4 1.125 0.3621916 0.3348249 0.3891862     2           2004
2     1 #F8766D 0.875 0.3628851 0.3388994 0.3877805     1           2004
3     1 #00BFC4 2.125 0.3107964 0.2823060 0.3398029     4           2006
4     1 #F8766D 1.875 0.3113829 0.2856144 0.3391679     3           2006
5     1 #00BFC4 3.125 0.3019772 0.2791706 0.3261124     6           2008
6     1 #F8766D 2.875 0.3030195 0.2814583 0.3247936     5           2008
y_plotlyDomain  xmin  xmax colour_plotlyDomain size linetype width alpha
1      0.3621916 1.125 1.125             Model 2  1.5        1     0    NA
2      0.3628851 0.875 0.875             Model 1  1.5        1     0    NA
3      0.3107964 2.125 2.125             Model 2  1.5        1     0    NA
4      0.3113829 1.875 1.875             Model 1  1.5        1     0    NA
5      0.3019772 3.125 3.125             Model 2  1.5        1     0    NA
6      0.3030195 2.875 2.875             Model 1  1.5        1     0    NA
hovertext
1 year: 2004<br />fit: 0.3621916<br />model: Model 2<br />lower: 0.3348249<br />upper: 0.3891862
2 year: 2004<br />fit: 0.3628851<br />model: Model 1<br />lower: 0.3388994<br />upper: 0.3877805
3 year: 2006<br />fit: 0.3107964<br />model: Model 2<br />lower: 0.2823060<br />upper: 0.3398029
4 year: 2006<br />fit: 0.3113829<br />model: Model 1<br />lower: 0.2856144<br />upper: 0.3391679
5 year: 2008<br />fit: 0.3019772<br />model: Model 2<br />lower: 0.2791706<br />upper: 0.3261124
6 year: 2008<br />fit: 0.3030195<br />model: Model 1<br />lower: 0.2814583<br />upper: 0.3247936
ROW COL  x.y SCALE_X SCALE_Y xaxis yaxis xanchor yanchor x_min x_max     y_min
1   1   1 Male       1       1 xaxis yaxis       y       x   0.4   5.6 0.1775765
2   1   1 Male       1       1 xaxis yaxis       y       x   0.4   5.6 0.1775765
3   1   1 Male       1       1 xaxis yaxis       y       x   0.4   5.6 0.1775765
4   1   1 Male       1       1 xaxis yaxis       y       x   0.4   5.6 0.1775765
5   1   1 Male       1       1 xaxis yaxis       y       x   0.4   5.6 0.1775765
6   1   1 Male       1       1 xaxis yaxis       y       x   0.4   5.6 0.1775765
y_max
1 0.5294233
2 0.5294233
3 0.5294233
4 0.5294233
5 0.5294233
6 0.5294233

The full reprex is below.

library(tibble)
library(ggplot2)
library(plotly)
tmp <- tibble(
  year = rep(2004,4), 
  x = factor(c(1,2,1,2), labels=c("Male", "Female")), 
  fit = c(0.3628851, 0.3698281, 0.3621916, 0.3689059), 
  lower = c(0.3388994,0.3408131,0.3348249,0.3419387), 
  upper = c(0.3877805, 0.3998003, 0.3891862, 0.3980086), 
  model = factor(c(1,1,2,2), labels=c("Model 1", "Model 2"))
)

g <- ggplot(tmp, aes(x=year, y=fit, colour=model, ymin=lower, ymax=upper)) + 
  geom_point(position=position_dodge(width=.5), size=3) + 
  geom_errorbar(width=0, position=position_dodge(width=.5), size=1.5) + 
  facet_wrap(.~x)

ggplotly(g)
#> Error in `$<-.data.frame`(`*tmp*`, "width", value = numeric(0)): replacement has 0 rows, data has 4

Created on 2020-02-25 by the reprex package (v0.3.0)

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 exécuter le reprex fourni avec ggplot2 et plotly, puis suivez ggplotly() à travers layers2traces() jusqu’à to_basic() pendant le traitement de la couche geom_errorbar. Comparez les colonnes de données des barres d’erreur avec les champs consultés à cet endroit ; le travail est terminé lorsque le graphique facetté fourni est converti avec succès sans l’erreur de taille de remplacement et que les tests associés couvrent ce cas.

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é
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

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