plotly / plotly/plotly.R

style(hoveron="fills") doesn't work with ggplotly() when there are multiple polygons with the same fill color

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

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

difficulty: high ggplotly
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ả

The following code based on the standard North Carolina shape-file fills counties by the values of BIR74, except that one county has been given an NA value for the variable.

library(ggplot2)
library(plotly)
library(sf)

nc_1 <-
  st_read(system.file("shape/nc.shp", package = "sf"), 
              quiet = TRUE) %>% 
  mutate(BIR74 = ifelse(NAME == "Ashe", NA, BIR74)) %>% 
  mutate(tooltip_text = ifelse(is.na(BIR74), 
                               paste0(NAME, " not reporting"), 
                               paste0(NAME, " reports ", BIR74)))
p_1 <-
  nc_1 %>% 
  ggplot() +
  geom_sf(aes(fill = BIR74, text = tooltip_text))

ggplotly(p_1, tooltip = "text") %>% 
  style(hoveron = "fills")

The custom tooltip indicates the missing value (hover over Ashe County) as expected.

The following code sets BIR74 to NA for two counties:

nc_2 <-
  st_read(system.file("shape/nc.shp", package = "sf"), 
          quiet = TRUE) %>% 
  mutate(BIR74 = ifelse(NAME %in% c("Ashe", "Alleghany"), NA, BIR74)) %>% 
  mutate(tooltip_text = ifelse(is.na(BIR74), 
                               paste0(NAME, " not reporting"), 
                               paste0(NAME, " reports ", BIR74)))
p_2 <-
  nc_2 %>% 
  ggplot() +
  geom_sf(aes(fill = BIR74, text = tooltip_text))

ggplotly(p_2, tooltip = "text") %>% 
  style(hoveron = "fills")

Hover over either Ashe or Alleghany and you get identical very long tooltips.

The output of plotly_json(p_2) indicates that Ashe and Alleghany have somehow been combined. See, e.g.:

json_2 <- plotly_json(p_2)
json_2$x$data %>%
  as.character() %>% 
  RJSONIO::fromJSON() %>% 
  .$data %>% 
  .[[100]] %>% 
  .[1: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

Chạy hai ví dụ North Carolina với ggplotly(), tooltip = "text" và style(hoveron = "fills"), sau đó kiểm tra plotly_json(p_2) như minh họa. So sánh cách các trường hợp có một NA và hai NA biểu diễn dữ liệu polygon; hoàn tất khi Ashe và Alleghany mỗi nơi hiển thị tooltip riêng thay vì một tooltip dài được gộp chung.

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
Đặc tả 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.