I have a dataset with the X and Y coordinates and I am trying to figure out a way to sort them in clockwise (or Anticlockwise) direction in R from the center. Assuming the median of latitude and longitude as the center.
The sample data:
df <- structure(list(name = c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J"), lat = c(22.57, 22.69, 22.72, 22.5, 22.66, 22.19, 22.6,
22.27, 22.31, 22.15), lon = c(88.69, 88.84, 88.77, 88.85, 88.63,
88.91, 88.54, 88.62, 88.78, 88.66)), class = "data.frame", row.names = c(NA,
-10L))

What I am looking for is say, the points from the above image can be sorted like this: G -> E -> A-> C -> B and so on.
So far, I have tried calculating the polar position with arc tan function and then sort them but that didn't yield a good result.
I have also tried the orderPoints function, but the ordering has been doubtful there too. The order I got was something like this: D-> F-> G-> B-> H-> J-> I-> E-> C-> A. While some of them seem to be in order, others are looking far off.
