plotly / plotly/plotly.R

legendrank (bar chart example)

Abierto
#2,233 1 comentario 1 reacción 0 asignados Ver en GitHub

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

This bug report concerns R plotly 4.10.1.
I was going to file a report regarding a more complex composite chart; involving bars and lines; as I noticed when there was an NA(or NaN) value to plot against the Y axis , the legend orders got scrambled. I was able to directly address this shortcoming in my own code by na.omit() on my input dataset. However , in the course of trying to simplify my code down to be more minimal for this reprex, I encountered a more basic issue of the legendrank seemingly not being respected

library(tidyverse)
library(plotly)
(tot_df <- structure(list(
  rank = structure(c(
    1L, 1L, 1L, 1L, 2L, 2L, 2L,
    2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L
  ), levels = c(
    "1", "2", "3",
    "4"
  ), class = "factor"), value = c(
    1, 0.316227766016838, 2, 0.447213595499958,
    3, 0.547722557505166, 4, 0.632455532033676, 5, 0.707106781186548,
    3, 0.547722557505166, 2, 0.447213595499958, 1, 0.316227766016838
  ), name = c(
    "stat1", "stat_2", "stat1", "stat_2", "stat1", "stat_2",
    "stat1", "stat_2", "stat1", "stat_2", "stat1", "stat_2", "stat1",
    "stat_2", "stat1", "stat_2"
  ), `Display name` = structure(c(
    1L,
    1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L
  ), levels = c(
    "Reference",
    "Current"
  ), class = "factor"), series_name_text = structure(c(
    1L,
    2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L
  ), levels = c(
    "Reference stat1",
    "Reference stat_2", "Current stat1", "Current stat_2"
  ), class = "factor"),
  my_legend_rank = c(
    1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
    3L, 4L, 1L, 2L, 3L, 4L
  )
), row.names = c(NA, -16L), class = c(
  "tbl_df",
  "tbl", "data.frame"
))
)


px <- plot_ly(
  data = tot_df,
  width = 800,
  height = 600,
  x = ~rank,
  y = ~value,
  name = ~series_name_text,
  legendrank = ~my_legend_rank,
  color = ~`Display name`,
  colors = c("green", "blue"),
  textposition = "none",
  type = "bar",
  opacity = .5,
  yaxis = "y"
) |> layout(legend = list(
  orientation = "h",
  xanchor = "center",
  yanchor = "bottom",
  y = -0.3,
  x = 0.5
))

# table(tot_df$series_name_text,tot_df$my_legend_rank
#                  1 2 3 4
# Reference stat1  4 0 0 0
# Reference stat_2 0 4 0 0
# Current stat1    0 0 4 0
# Current stat_2   0 0 0 4

plotly_json(px)

image

It seems to me that based on legendrank 'Reference stat1 should be the first i.e. leftmost trace name observed within the legend box, and this isnt the case, the first seen is Current stat1, that should be in 3rd position...)
Is there a gotcha here ? some incorrect setup ? something that invalidates the use of legendrank ?

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Ejecuta el reprex de R proporcionado e inspecciona plotly_json(px), centrándote en cómo se representa el mapeo de legendrank para las trazas de barras. Compara el orden de la leyenda generado con los rangos solicitados; se considera terminado si las trazas aparecen en orden de rango o si el issue queda explicado y cubierto por una prueba de regresión adecuada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
plotly, r
Área
data-visualization
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.