plotly / plotly/plotly.R

legendrank scrambled by fillcolor with type='scatter'

Đang mở
#2,282 0 bình luận 0 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ả

Expected behavior

When making a stacked area chart, the ordering of the legend values follows the ordering of the legendrank argument.

Actual behavior

When making a stacked area chart, the ordering of the legend values depends on the legendrank argument in combination with the alphabetical ordering of the fillcolor argument. Somehow the fillcolors seem to be scrambling the order.

Here's an example:

# The goal is to make a stacked area chart, where each fill color is a severity
# level. Then, the legend should be ordered by severity
library(plotly)

severities = c('Mild', 'Moderate', 'Severe')
severity_colors = c('#FF0000', '#440000', '#AA0000')
# ^ colors chosen specifically to be out of alphabetical order
severity_color_dict = setNames(severity_colors, severities)

timeline = data.frame(Time = rep(1:15, 3),
                      coverage = rep(1, 45),
                      Severity = factor(rep(severities, each = 15)))
timeline$fill = severity_color_dict[timeline$Severity]

# default order
plot_ly(timeline, x = ~Time, y = ~coverage, name = ~Severity, type = 'scatter',
        mode = 'none', stackgroup = 'one', groupnorm = '')

# add fillcolor-- now the legend is in alphabetical order of fillcolor
plot_ly(timeline, x = ~Time, y = ~coverage, name = ~Severity, type = 'scatter',
        mode = 'none', stackgroup = 'one', groupnorm = '', fillcolor = ~fill)

# this should be ordered by Severity, but it's still in alphabetical order of
# fillcolor
plot_ly(timeline, x = ~Time, y = ~coverage, name = ~Severity, type = 'scatter',
        mode = 'none', stackgroup = 'one', groupnorm = '', fillcolor = ~fill,
        legendrank = ~as.integer(Severity))

# The intended order can only be acheived by using the alphabetical ordering of
# the fill colors to "unscramble" the legendrank
unscramble_dict = order(severity_colors)
plot_ly(timeline, x = ~Time, y = ~coverage, name = ~Severity, type = 'scatter',
        mode = 'none', stackgroup = 'one', groupnorm = '', fillcolor = ~fill,
        legendrank = ~unscramble_dict[as.integer(Severity)])

Session info

R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] plotly_4.10.2 ggplot2_3.4.2

loaded via a namespace (and not attached):
 [1] magrittr_2.0.3    tidyselect_1.2.0  munsell_0.5.0     viridisLite_0.4.2 colorspace_2.1-0  R6_2.5.1          rlang_1.1.1      
 [8] fastmap_1.1.1     fansi_1.0.4       httr_1.4.6        dplyr_1.1.2       tools_4.1.2       parallel_4.1.2    grid_4.1.2       
[15] data.table_1.14.8 gtable_0.3.3      utf8_1.2.3        cli_3.6.1         withr_2.5.0       ellipsis_0.3.2    crosstalk_1.2.0  
[22] htmltools_0.5.5   yaml_2.3.7        lazyeval_0.2.2    digest_0.6.31     tibble_3.2.1      lifecycle_1.0.3   tidyr_1.3.0      
[29] purrr_1.0.1       htmlwidgets_1.6.2 vctrs_0.6.2       glue_1.6.2        compiler_4.1.2    pillar_1.9.0      generics_0.1.3   
[36] scales_1.2.1      jsonlite_1.8.5    pkgconfig_2.0.3  

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

Bắt đầu bằng cách chạy các ví dụ R có thể tái hiện sử dụng plot_ly với type='scatter', stackgroup, fillcolor và legendrank. Theo dõi cách thứ tự chú giải của biểu đồ vùng xếp chồng phản hồi với các đối số đó; được xem là hoàn tất khi thứ tự chú giải luôn nhất quán theo legendrank, bất kể thứ tự của fillcolor, đồng thời vẫn giữ nguyên hành vi đã báo cáo.

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

Đánh giá

Công nghệ
r
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 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.