plotly / plotly/plotly.R

ggplotly shows wrong tooltip with geom_sf() and discrete fill scale

Đang mở
#1,671 1 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ả

This is a copy of my question on Stack Overflow, because I suspect it's not intended behaviour.

I'm trying to create maps that'll show tooltips on hover with plotly. In the maps below, I've tried to make it show the name and the area of each place.

The first map, which has a continuous fill scale, shows the tooltip I'm asking for. But the second map, doesn't. The only difference is that the fill scale is discrete.

What's going on, and how can I fix it?

library(pacman)
p_load(sf, ggplot2, dplyr, plotly)

nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) %>% 
    mutate(x = factor(c(rep("a", 50), rep("b", 50))),
           TEXT = paste(NAME, AREA))

# It works when I've got a continuous fill scale
p1 <- nc %>% 
    ggplot() +
    geom_sf(aes(fill = AREA, text = TEXT))
#> Warning: Ignoring unknown aesthetics: text

ggplotly(p1, tooltip = "text") %>% 
    style(hoverlabel = list(bgcolor = "white"), hoveron = "text")

map showing the correct tooltip

Why does this map say "a"?

# But it doesn't work with a discrete fill scale
p2 <- nc %>% 
    ggplot() +
    geom_sf(aes(fill = x, text = TEXT))
#> Warning: Ignoring unknown aesthetics: text

ggplotly(p2, tooltip = "text") %>% 
    style(hoverlabel = list(bgcolor = "white"), hoveron = "text")

map showing the wrong tooltip

EDIT: turns out even the continuous map sometimes shows weird tooltips. Some areas show the right one, as above, others show "Trace XX":

continuous map showing wrong tooltip in some areas

From Stack Overflow answer: someone suggested removing hoveron = "text", which partially works. It shows the right tooltips, but only on the outlines of the shapes, so you don't know which shape it's referring to. Some shapes you can't get the tooltip at all, such as this one:
image

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 cung cấp, sử dụng ggplotly(), geom_sf(), các thang màu tô liên tục và rời rạc, cùng với tooltip = "text". So sánh các tooltip được tạo cho p1 và p2, bao gồm cả các trường hợp sử dụng hoveron = "text"; hoàn tất khi mỗi đa giác luôn hiển thị NAME và AREA của nó thay vì "a" hoặc "Trace XX".

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
38/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.