plot_mapbox() causes precision and slowness issues with hover and highlight features
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- R
- Estrellas
- 2.7k
- Forks
- 641
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
Hi folks, choropleth maps using plotly + simple features + mapbox as base map is the perfect combination in my opinion, it is really beautiful and functional.
However, I have not been able to use it because, when plot_mapbox() is used as opposed to plot_ly(), hover gets very imprecise and the highlight very slow.
Consider this MWE:
devtools::install_github("ipeaGIT/geobr", subdir = "r-package")
library(geobr)
library(sf)
library(plotly)
mapbox_token <- "your mapbox token"
Sys.setenv('MAPBOX_TOKEN'=mapbox_token)
data_sf <- geobr::read_region(year=2010) %>%
sf::st_cast("MULTIPOLYGON")
plot_mapbox() %>%
add_sf(
data = data_sf %>% highlight_key(~name_region),
split = ~name_region, showlegend = FALSE,
text = ~paste0(name_region,": ",code_region),
hoverinfo = "text"
) %>%
highlight(on = "plotly_hover", off = "plotly_doubleclick")
For example, as shown in the picture below, while the mouse is pointing to the blue region, the hover shows the info from the red region.

Another example, here the mouse is pointing right in the middle of the blue region but no hover data is shown.

And finally, the highlight_key() is a very valuable feature, nonetheless it is too slow and laggy to be effectively used with plot_mapbox(), at least in my machine, do you have different experiences with it?
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
system code page: 65001
attached base packages:
[1] stats graphics grDevices utils
[5] datasets methods base
other attached packages:
[1] geobr_1.6.6 sf_1.0-6 plotly_4.10.0
[4] ggplot2_3.3.5
Thank you
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza ejecutando el MWE proporcionado con plot_mapbox(), add_sf(), highlight_key() y highlight(), y luego compara su comportamiento de hover con plot_ly(). Investiga la ruta de plot_mapbox y la interacción entre el objetivo del hover y el resaltado. Se considera completado cuando el hover identifica de forma consistente la región bajo el puntero y el resaltado responde correctamente para el mapa mostrado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- r
- Área
- data-visualization
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100