No way to make legend order exactly match bar order in relative stacked bar plot
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- R
- Estrellas
- 2.7k
- Forks
- 641
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza reproduciendo el ejemplo de R proporcionado con plot_ly(), add_bars(), barmode = "relative" y la configuración actual de la leyenda. Investiga si el comportamiento solicitado puede admitirse para apilamientos negativos y positivos; se considera terminado cuando el orden de la leyenda coincide exactamente con el orden visible de las barras, o cuando se documentan la limitación y el comportamiento de ordenación elegido.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- r
- Área
- data-visualization
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100