ggplotly shows wrong tooltip with geom_sf() and discrete fill scale
Personne n'a encore pris cette issue.
- Langage dominant
- R
- Étoiles
- 2.7k
- Forks
- 641
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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:

Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par exécuter les exemples R fournis en utilisant ggplotly(), geom_sf(), les échelles de remplissage continues et discrètes, ainsi que tooltip = "text". Comparez les tooltips générés pour p1 et p2, y compris les cas utilisant hoveron = "text" ; c'est terminé lorsque chaque polygone affiche systématiquement son NAME et son AREA plutôt que "a" ou "Trace XX".
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- plotly, r
- Domaine
- data-visualization
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100


