ggiraph
ggiraph copied to clipboard
Workaround to get highlighting of nearest point
As this is a feature that is being worked on. (seen it stated somewhere anyway) I would like to present a workaround until it is available natively in ggiraph.
library(tidyverse)
library(ggiraph)
library(ggvoronoi)
tibble(ids = 1:100,
x = rnorm(100),
y = rnorm(100)) %>%
mutate(rownumber = row_number()) ->
fake_data
fake_data %>% as.data.frame() %>%
voronoi_polygon(x = "x",y = "y") %>%
fortify() %>%
as_tibble() %>%
mutate(rownumber = id %>% parse_number()) %>%
select(-id) %>%
full_join(distinct(fake_data, ids, rownumber)) -> fake_data_voronoi
fake_data %>%
ggplot(aes(x = x,
y = y,
tooltip=ids,
data_id=ids))+
geom_point_interactive()+
geom_polygon_interactive(aes(x=long,
y=lat,
group=group),
data=fake_data_voronoi,
colour = NA,
alpha=.01, # this is as low it can go
hover_css = "stroke-width:0;")->
plot_obj
girafe(ggobj = plot_obj)