I am trying to assign points into groupings based on Euclidean distance. For example, in the data below there are three points that represent three different groups (One, Two, Three
, the non-green points on the figure). I would like to assign the remaining points (Scatter
the green points) into a grouping based on the minimum Euclidean distance (i.e. change Scatter
to the closest of the One
Two
or Three
points.
I was trying to do this outside of kmeans
or other clustering function and simply use the minimum Euclidean distance, but welcome and appreciate suggestions.
set.seed(123)
Data <- data.frame(
x = c(c(3,5,8), runif(20, 1, 10)),
y = c(c(3,5,8), runif(20, 1, 10)),
Group = c(c("One", "Two", "Three"), rep("Scatter", 20))
)
ggplot(Data, aes(x, y, color = Group)) +
geom_point(size = 3) +
theme_bw()