data(plants_df, plants_xy)
# Create spatial fold centered on first coordinate
fold <- make_spatial_fold(
xy.i = plants_xy[1, ],
xy = plants_xy,
training.fraction = 0.6
)
# View training and testing record IDs
fold$training
fold$testing
# Visualize the spatial split (training = red, testing = blue, center = black)
if (interactive()) {
plot(plants_xy[c("x", "y")], type = "n", xlab = "", ylab = "")
points(plants_xy[fold$training, c("x", "y")], col = "red4", pch = 15)
points(plants_xy[fold$testing, c("x", "y")], col = "blue4", pch = 15)
points(plants_xy[1, c("x", "y")], col = "black", pch = 15, cex = 2)
}
Run the code above in your browser using DataLab