I have a plot like
My goal is to filter out all the data that falls inside the inner circle.
I have tried ways to filter only by the data that draws the circle, problem is that is has X and Y values and they're in all 4 spaces of a cartesian map, so if a point is above may be okay (filtering by values greater than something) but that would filter out values that are still outside the inner circle but below it.
I've also tried to do things using integrals but my math is rusty. Integrals suppose to be able to recognise values under the curve. If the curve draws the inner circle maybe I'm able to filter values out. For me, right know, that's more easy to say than to do, so help is appreciated.
PS: non-native english speaker here, so pardon me.
The circles are created by:
radii=c(sqrt(1/2),1)
theta <- seq(0, 2 * pi, length = 500)
#Inner Circle:
xtemp1=radii[1]*cos(theta)
ytemp1=radii[1]*sin(theta)
circ1=as.data.frame(cbind(xtemp1,ytemp1))
#Outer Circle:
xtemp2=radii[2]*cos(theta)
ytemp2=radii[2]*sin(theta)
circ2=as.data.frame(cbind(xtemp2,ytemp2))
Here's a small part of the data (named temp):
Comp_1,Comp_2
0.253,-0.29
-0.23,0.222
-0.384,0.432
-0.032,0.805
-0.261,0.265
-0.181,0.344
-0.133,-0.436
-0.358,-0.004
-0.139,-0.314
0.303,0.257
-0.131,0.602
And for the plot:
#Plot
p1=ggplot(data=temp, aes(x=Comp_1, y=Comp_2)) + geom_point() +
scale_x_continuous(limits=c(-1,1), breaks=seq(-1,1,by=0.1)) +
scale_y_continuous(limits=c(-1,1), breaks=seq(-1,1,by=0.1))
#Circle
p1=p1 + geom_polygon(data=circ1, aes(x=xtemp1, y=ytemp1),size=0.5,inherit.aes = F, colour="black", fill=NA, alpha=0.5) +
geom_polygon(data=circ2, aes(x=xtemp2, y=ytemp2),size=0.5,inherit.aes = F, colour="black", fill=NA, alpha=0.5)
This sounds like a Point in Polygon problem (https://en.wikipedia.org/wiki/Point_in_polygon) . The point.in.polygon() function in the sp library might be usefull.
point.in.polygon(Comp_1,Comp_2,xtemp1,ytemp1)