plotly / plotly/plotly.R

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

Aperta
#1,641 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

difficulty: high ggplotly
Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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]

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui i due esempi di North Carolina con ggplotly(), tooltip = "text" e style(hoveron = "fills"), quindi esamina plotly_json(p_2) come mostrato. Confronta il modo in cui i casi con uno e con due NA rappresentano i dati dei poligoni; il lavoro è completato quando Ashe e Alleghany visualizzano ciascuno il proprio tooltip invece di un unico tooltip lungo e combinato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
r
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.