plotly / plotly/plotly.R

ggplotly with points, error bars and facets error

Aperta
#1,710 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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

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)

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

Inizia eseguendo il reprex fornito con ggplot2 e plotly, quindi segui ggplotly() attraverso layers2traces() fino a to_basic() durante l’elaborazione del layer geom_errorbar. Confronta le colonne di dati delle barre d’errore con i campi a cui si accede in quel punto; il lavoro è completo quando il grafico sfaccettato fornito viene convertito correttamente senza l’errore relativo alla dimensione della sostituzione e i test correlati coprono il caso.

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

Valutazione

Stack tecnologico
r
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.