plotly / plotly/plotly.R

Categoryorder not working when specifying plot type

Offen
#2,082 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

When using the category order parameter, no plot is generated if the plot type is specified in the plot_ly call:

p <- plotly::plot_ly(type = 'bar')
colNames <- names(iris)
colNames <- colNames[-which(colNames == 'Species')]

for(trace in colNames){
  p <- p %>% plotly::add_trace(data= iris, x = ~ Species, y = as.formula(paste0("~`", trace, "`")), name = trace)
}

p  %>% layout(xaxis = list(categoryorder='total descending'))

With the following warning, which I don't understand since I'm not combining discrete and non-discrete data in the same axis:

Warning message:
Can't display both discrete & non-discrete data on same axis 

If I specify the type in add_trace instead of the plot, then it works correctly and the warning is gone:

p <- plotly::plot_ly()
colNames <- names(df)
colNames <- colNames[-which(colNames == 'Species')]

for(trace in colNames){
  p <- p %>% plotly::add_trace(type = 'bar', data= iris, x = ~ Species, y = as.formula(paste0("~`", trace, "`")), name = trace)
}

p %>% layout(xaxis = list(categoryorder='total descending'))

Maybe this is the intended behavior? If so, why does specifying the type in the traces works and not in the plot? The warning seems unclear to me.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die bereitgestellte R-Reproduktion mit iris auszuführen, und vergleiche plot_ly(type = 'bar') mit add_trace(type = 'bar'). Verfolge, wie plot_ly und add_trace den type weitergeben und wie layout(xaxis = list(categoryorder = 'total descending')) mit den daraus resultierenden Traces umgeht. Als erledigt gilt die Aufgabe, wenn die Reproduktion keine Warnung mehr ausgibt und die Kategorie-Reihenfolge konsistent funktioniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.