I have a scatter plot which I generate using below code
set.seed(10)
mydata <- data.frame(x1 = rnorm(1000), x2 = rnorm(1000))
ind <- replicate(3, sample(nrow(mydata), 500))
head(ind)
feature1 = mydata[ind[,1], "x1"]
feature2 = mydata[ind[,2], "x2"]
# start with a plot
plot(feature1, feature2, pch=4 , col="black")
I want to identify one data point and color it using a different color, which I do using below code
plot(feature1, feature2, pch=4, col=ifelse((feature1 > 2.6 & feature1 < 2.7 ), "red", "black"))
Now, I would like to draw a circle around this point(which is marked in RED) and connect nearest neighboring N points to this point(where N should be a variable)
How can I do it using R?
Here is what I intend to get in my output