No way to make legend order exactly match bar order in relative stacked bar plot
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
Sometimes we want to plot negative values below x axis in a stacked bar plot. This can be done with barmode as "relative".
Further, I want to make the legend order exactly match the bar order in plot. However the positive bars stack from middle to top, negative bars stack from middle to down, thus no matter how I arrange the variable levels, there is no way to make the legend order exactly match bar order.
library(plotly)
library(data.table)
set.seed(42)
dt_test <- data.table(x = rep(1:5, each = 6), variable = rep(letters[1:6], 5), value = sample(10:40, 30))
dt_test[variable %in% letters[3:5], value := -value]
dt_test[, variable := factor(variable, levels = c("c", "d", "e", "a", "b", "f"))]
plot_ly(dt_test) %>%
add_bars(x = ~x, y = ~value, color = ~variable) %>%
layout(barmode = 'relative', legend = list(traceorder = "reversed"))

I'm not sure how this can be done, unless we
- change the stack order in negative part as bottom up
- or can arrange legend order freely without changing bar stack order
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l'esempio R fornito con plot_ly(), add_bars(), barmode = "relative" e l'impostazione corrente della legenda. Verifica se il comportamento richiesto può essere supportato per gli stack negativi e positivi; il lavoro è completato quando l'ordine della legenda corrisponde esattamente all'ordine visibile delle barre, oppure quando sono documentati il limite e il comportamento di ordinamento scelto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- r
- Ambito
- data-visualization
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100