ggplotly shows wrong tooltip with geom_sf() and discrete fill scale
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")
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")
EDIT: turns out even the continuous map sometimes shows weird tooltips. Some areas show the right one, as above, others show "Trace XX":
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:

Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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


