plotly / plotly/plotly.R

legendrank (bar chart example)

Đang mở
#2,233 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
R
Star
2.7k
Fork
641
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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 ?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Chạy reprex R được cung cấp và kiểm tra plotly_json(px), tập trung vào cách ánh xạ legendrank được biểu diễn cho các trace dạng thanh. So sánh thứ tự chú giải được tạo ra với các rank được yêu cầu; được xem là hoàn thành khi các trace xuất hiện theo thứ tự rank hoặc issue được giải thích và được bao phủ bởi một regression test phù hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
plotly, r
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.