map a hex to original data points in geom_hex

38 Views Asked by At

I am trying to map hex from geom_hex to original data points. For example I want to find points in the iris dataframe that are related to highlighted hex (red circle).

data("iris")
rownames(iris) <- paste0("R", 1:nrow(iris))
plt <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_hex(bins=20, color = "white")
plt

plt

I tried ggplot_build which has 'count' but can't find any information that links to the original data.

g <- ggplot_build(plt)
head(g$data[[1]])
0

There are 0 best solutions below