plotly / plotly/plotly.R

Unexpected behavior with geom_text layers in ggplotly

Đang mở
#539 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ả

I'm getting unexpected behavior when assigning color to geom_text() in ggplotly

This is slightly related to issue #469 (and I'll use the same example data) where a geom_text layer wasn't appearing at all. That's no longer the case. The text appears fine (yeah!) but the interactivity isn't functioning as I would expect (rats!).

Here's some data:

tempDf <- data.frame("x" = c(22.1, 22.1, 14.4, 32.1, 22.0, 32.1, 84.3, 15.9, 15.9, 11.8, 11.8, 25.1, 15.7, 22.4, 35.1, 36.6, 70.4, 65.2, 42.9, 36.3, 47.8),
"y" = c(21.0, 21.0, 39.8, 47.6, 69.6, 95.0, 94.8, 17.3, 17.3, 27.6, 27.6, 90.3, 85.7, 94.1, 72.3, 71.5, 100.0, 92.4, 76.9, 34.6, 4.9),
"endX" = c(NA, 13.1, 31.9, 22.0, 29.7, 84.3, 94.4, NA, 15.1, NA, 25.0, 14.3, 22.4, 59.6, NA, 70.4, 65.9, 44.2, 38.3, 48.3, 72.1),
"endY" = c(NA, 33.3, 46.0, 69.6, 93.5, 94.8, 51.6, NA, 22.1, NA, 90.3, 85.4, 94.1, 96.8, NA, 100.0, 91.5, 80.8, 37.1, 5.2, 36.9),
"index" = c(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0),
"string"= c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0) )

And here's my plot:

example <- ggplot(tempDf, aes(x=x, y=y, color=as.factor(index))) + geom_point(size = 4, shape = 0) + 
    geom_text(aes(label= string), size = 2) + 
    geom_segment(data = tempDf, aes(x=x, xend=endX, y=y, yend=endY, group = index, color=as.factor(index)), size = .3, arrow=arrow(length=unit(0.3,"cm")) ) + xlim(0,100) + ylim(0,100) +
    theme(panel.grid.minor = element_blank(), 
        panel.grid.major = element_blank(), 
        panel.background = element_rect(fill = "grey90"), 
        axis.ticks.x = element_blank(), 
        axis.ticks.y = element_blank(), 
        axis.text.x = element_blank(), 
        axis.text.y = element_blank(),  
        #legend.title=element_blank(),
        #legend.margin=unit(-.4, "cm"),
        plot.margin=unit(c(0, 0, 1.3, -1), units="cm"),  #top, right, bottom, left
        legend.text = element_text(size = 14, face = "bold") ) + 
    xlab("") + ylab("")
ggplotly(example)

There are three colored sequences (at least that's how I'll refer to them here, one red, one green and one blue). I can toggle off/on ant of the individual color sequences. When I do that all of the elements toggle off (the segments, the text (number) and the shape; arrows aren't yet supported in plotly). Here, I've toggled the red off. This is as I would expect (and what I'm after).
screen shot 2016-04-06 at 5 25 53 pm
However, if I change the color of the geom_text like this (the only difference is that I'm adding: 'color = "black"' to the geom_text layer)

example <- ggplot(tempDf, aes(x=x, y=y, color=as.factor(index))) + geom_point(size = 4, shape = 0) + 
        geom_text(aes(label= string), size = 2, color = "black") + 
        geom_segment(data = tempDf, aes(x=x, xend=endX, y=y, yend=endY, group = index, color=as.factor(index)), size = .3, arrow=arrow(length=unit(0.3,"cm")) ) + xlim(0,100) + ylim(0,100) +
        theme(panel.grid.minor = element_blank(), 
            panel.grid.major = element_blank(), 
            panel.background = element_rect(fill = "grey90"), 
            axis.ticks.x = element_blank(), 
            axis.ticks.y = element_blank(), 
            axis.text.x = element_blank(), 
            axis.text.y = element_blank(),  
            #legend.title=element_blank(),
            #legend.margin=unit(-.4, "cm"),
            plot.margin=unit(c(0, 0, 1.3, -1), units="cm"),  #top, right, bottom, left
            legend.text = element_text(size = 14, face = "bold") ) + 
        xlab("") + ylab("")
ggplotly(example)

Now when I toggle off any of the colored sequences, the black numbers are left behind. Here I've left the red layer 'on') but notice all of the black letters from the other sequences are left still showing.
screen shot 2016-04-06 at 5 25 34 pm

That's not right, is it? The behavior I'd expect (and what I'm hoping for) is that the black numbers also toggle off with the rest of the elements.

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 tái hiện ví dụ ggplotly được cung cấp với geom_point, geom_text và geom_segment, so sánh màu được ánh xạ với màu văn bản đen cố định. Theo dõi cách ggplotly nhóm các layer để bật tắt trong chú giải. Hoàn tất khi các nhãn geom_text màu đen được tắt cùng với chuỗi màu tương ứng, trong khi hành vi hiện tại vẫn được giữ nguyên.

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