plotly / plotly/plotly.R

Grouping by color and/or symbol changes the order of error_y bars

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

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

bug priority: high
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ả

Reopening issues #762 and #1110, this is still happening in 2019 and maybe I found the cause.
Briefly, error bars displayed by error_x and error_y appear in the wrong order when grouping data by color or (as I found) symbol. Recycling @Cristoforetti 's code from #1110:

df<-data.frame("X"=c(1:20),
"Y"=c(1:20),
"SD"=c(1:20),
"G"=c(rep("A",3),rep("B",5),rep("C",4),rep("D",5),rep("A",3)),
"g"=c(rep("a",2),rep("b",5),rep("c",4),rep("d",5),rep("e",4))
)
# no grouping; error bars correct
p1<-plot_ly(df,
            x=~X,
            y=~Y,
            type="scatter",
            mode="markers",
            error_y =list(
              array=~SD,
              thickness=1
            )
)
# grouping by color; error bars wrong
p2<-plot_ly(df,
            x=~X,
            y=~Y,
            color=~G,
            type="scatter",
            mode="markers",
            error_y =list(array=~SD,
                          thickness=1
            )
)
subplot(p1,p2)

image
I found that the correct behaviour (error bars associated with the correct data points) can be restored by passing a version of the input dataframe order-ed by the color column:

# ordering the input data frame by the color column yields the correct behaviour
p3<-plot_ly(df[order(df$G),],
            x=~X,
            y=~Y,
            color=~G,
            type="scatter",
            mode="markers",
            error_y =list(array=~SD,
                          thickness=1
            )
)
subplot(p1,p2,p3)

image
The same happens when ordering by symbol: the error bars are screwed up unless df is order-ed by the symbol column. When using both color and symbol, one must order by both the color column and the symbol column in this order:

# using "G" for color and "g" for symbols; ordering by G, then g yields the correct behaviour
p4<-plot_ly(df[order(df$G,df$g),],
            x=~X,
            y=~Y,
            symbol=~g,
            color=~G,
            type="scatter",
            mode="markers",
            error_y =list(array=~SD,
                          thickness=1
            )
)
# ordering by g, then G yields the wrong behaviour
p5<-plot_ly(df[order(df$g,df$G),],
            x=~X,
            y=~Y,
            symbol=~g,
            color=~G,
            type="scatter",
            mode="markers",
            error_y =list(array=~SD,
                          thickness=1
            )
)
subplot(p4,p5)

image

What seems to be happening here is that color and symbol are reordering the (copy of) df handled by plotl_ly, but for some reason the reordering only affects the columns identified by x, y, color and symbol; as a consequence, the column used by error_y is now in the wrong order, and error bars are associated with the wrong data points. Ordering the df prior to calling plot_ly, or passing an ordered version of it, solves the issue. Still, it would be great to see this fixed in future versions of plotly.

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ụ plot_ly và subplot có thể tái hiện với data frame được cung cấp, đồng thời so sánh các đầu vào đã nhóm và được sắp xếp trước. Theo dõi hành vi nhóm đối với màu và ký hiệu, đồng thời xác minh rằng các giá trị error_y vẫn được liên kết với các điểm ban đầu của chúng; được xem là hoàn tất khi các thanh sai số vẫn được căn chỉnh chính xác mà không cần sắp xếp thủ công.

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ó
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
45/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.