I am using geom_ellipse
to create an ellipse on faithful
dataset.
Here is the code:
t <- position_nudge(x=-1,y=-0.5)
obj <- ggplot(faithful, aes(waiting, eruptions))+
geom_point()+ geom_ellipse(aes(x0 = 70, y0 = 3, a= 3, b = 10,angle = pi/3),color="red",
position = t)
I want to extract the points/data that are present within the ellipse? How can I do that? I tried what was done here , but it does not work for geom_ellipse.
The thing with
geom_ellipse
is that when you look at the data of the layer withggplot_build
, you can see that the ellipse is shown multiple times in a data loop. So what you could do is get a first copy of the values like 272 values (same as your data). Based on the answer you can do the following:Created on 2022-12-17 with reprex v2.0.2
When you check the
dat
dataframe, you can see which points are in the ellipse.