Saya telah menemukan solusinya! Untuk semua yang lain, yang mencari jawaban juga, cara saya menyelesaikannya:
# Load library
library(sf)
# create points data
m <- matrix(c(10, 10, 30, 30, 15, 20), nrow = 3, byrow = TRUE)
multipoints <- st_multipoint(m, dim = "XY")
# save ranges of coordinates
x.range <- max(m[,1]) - min(m[,1])
y.range <- max(m[,2]) - min(m[,2])
# order by greatest range
if (x.range > y.range) {
sort.id <- order(m[,1])
} else if (y.range > x.range) {
sort.id <- order(m[,2])
} else if (y.range == x.range) {
sort.id <- order(m[,2])
}
# creat lines by previous sorting and save them in the list
lines <- lapply(1:(length(sort.id)-1), function(i) {
st_linestring(rbind(multipoints[sort.id[i],], multipoints[sort.id[i+1],]))
})
# plot results
plot(multipoints)
plot(lines[[1]], col = "orange", lwd = 2, add = TRUE)
plot(lines[[2]], col = "green", lwd = 2, add = TRUE)
Meskipun demikian, sekali lagi terima kasih atas bantuan Anda!