style(hoveron="fills") doesn't work with ggplotly() when there are multiple polygons with the same fill color
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- R
- Sterne
- 2.7k
- Forks
- 641
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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]
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe die beiden North-Carolina-Beispiele mit ggplotly(), tooltip = "text" und style(hoveron = "fills") aus und untersuche anschließend plotly_json(p_2) wie gezeigt. Vergleiche, wie die Fälle mit einem NA und mit zwei NA die Polygondaten darstellen; abgeschlossen ist die Aufgabe, wenn Ashe und Alleghany jeweils ihren eigenen Tooltip anzeigen statt eines einzigen kombinierten langen Tooltips.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- r
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100