In short: I'm looking for a way to get the exact coordinates of a series of mouse positions (by clicks) in the interactive x / y scatter graph displayed by ggplot2and ggplotly.
I know that plotly(and several other interactive build packages for R) can be combined with Shiny, where choosing box- or lazzo can return a list of all data points in the selected subspace. However, this list will be HUGE in most data sets that I analyze, and I need to be able to make the analysis reproducible in the R-marking format (write a few, mostly less than 5-6, the coordinates of the points are much more readable). In addition, I need to know the exact position of the clicks in order to be able to extract points within the same polygon of points in another data set, so the list of points within the selection in the same data set is not useful.
The function grid.locator()from the grid package does almost what I'm looking for (the one wrapped in fx gglocator ), however I hope there is a way to do the same in an interactive plot, plotly(or maybe something that I don’t know?) , since datasets are often HUGE (see graph below) and, therefore, the ability to interactively enlarge and display an image is greatly appreciated during several iterations of analysis.

Usually I have to scale the axes several times to simulate the scaling and shutdown, which exhausts many times when executed. As you can see in the above graph, there is a lot of information on the sections (the graph takes about 300 MB in memory).
reprex , , grid.locator :
library(ggplot2)
library(grid)
p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point()
locator <- function(p) {
ggobj <- ggplot_build(p)
xr <- ggobj$layout$panel_ranges[[1]]$x.range
yr <- ggobj$layout$panel_ranges[[1]]$y.range
selection <- data.frame(x = as.numeric(), y = as.numeric())
colnames(selection) <- c(ggobj$plot$mapping$x, ggobj$plot$mapping$y)
suppressWarnings(print(ggobj$plot))
panels <- unlist(current.vpTree()) %>%
grep("panel", ., fixed = TRUE, value = TRUE)
p_n <- length(panels)
seekViewport(panels, recording=TRUE)
pushViewport(viewport(width=1, height=1))
for (i in 1:10){
tmp <- grid.locator('native')
if (is.null(tmp)) break
grid.points(tmp$x,tmp$y, pch = 16, gp=gpar(cex=0.5, col="darkred"))
selection[i, ] <- as.numeric(tmp)
}
grid.polygon(x= unit(selection[,1], "native"), y= unit(selection[,2], "native"), gp=gpar(fill=NA))
return(selection)
}
locator(p)
point.in.polygon .
, , 100x100, , plotly_click event_data() Shiny, .
, , .
-