#I am creating an interactive map (shape) using Plotly in R. The map displays #frequencies in different departments. However, when hovering over the center #of the polygons, the tooltip with the department information does not appear. #The tooltip only appears when hovering over the edges of the polygons.
#I have tried using the layer and position properties in the tooltip #configuration, but the tooltip still doesn't appear consistently in the center #of the polygons.
#I would appreciate any suggestions or solutions to make the tooltip appear in #the center of the polygons when hovering over the map.
maa = read_sf("map.shp")
map = map %>% mutate(across(c("Frecuency", "Im", "Fo", "April", "July"),
~ifelse(is.na(.), 0, .)))
g_map = map %>%
ggplot(aes(fill = Frecuency, text = paste("Dp: ", NAME, "
",
"Frecuency: ", Frecuency, "
",
"I: ", Im, "
",
"F: ", Fo, "
",
"Abril: ", April, "
",
"Julio: ", July))) +
geom_sf() +
scale_fill_gradient(low = "white", high = "darkblue") +
labs(fill = "Scale", title = "Title") +
theme_minimal() +
theme_void()+
theme(axis.line = element_blank())
Convert to plotly
g_mapa_int = ggplotly(g_map, tooltip = "text")%>%
config(displayModeBar = FALSE) %>%
config(showLink = FALSE)
g_mapa_int