LKremer/ggpointdensity

Inspect neighbors

Okinur opened this issue · 1 comments

Hi.
Sorry for the question but I can't find by myself.
Is it possible see the number of neighbors for each point as a column of a dataframe?
I tried to storage the plot in the environment but I can not find the information about the "colour" factor.
Thank you in advance!

Hi @Okinur ,
In ggplot2 can see the full dataframe, including all computed stats such as n_neighbors or density with the ggplot_build() function. Like this:

p <- ggplot(data = dat, mapping = aes(x = x, y = y)) +
  geom_pointdensity()

df <- ggplot_build(p)$data

And then df contains everything you need. df should have a column callled density or n_neighbors depending on which version of ggpointdensity you're using, which is what you're looking for.
I hope this helps!