I have a bunch of points that I'd like to assign zones to in a grid. My points are from -100:100 along the x-axis and -42.5:42.5 along the y-axis. I want to create an overall 10x7 grid, which means the individual boxes are 20x12.143. Below is a re-prex example of the data and with gridlines indicating how I want the data divvied up.
x <- seq(-100, 100, length.out = 50)
y <- seq(-42.5, 42.5, length.out = 50)
points <- merge(x, y)
points %>%
ggplot() +
geom_point(aes(x, y), color = "lightblue") +
theme_minimal() +
#start of grid points
geom_segment(aes(x = -100, xend = -100, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = -80, xend = -80, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = -60, xend = -60, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = -40, xend = -40, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = -20, xend = -20, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = 0, xend = 0, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = 80, xend = 80, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = 60, xend = 60, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = 40, xend = 40, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = 20, xend = 20, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = 100, xend = 100, y = -42.5, yend = 42.5)) +
geom_segment(aes(x = -100, xend = 100, y = -30.357, yend = -30.357)) +
geom_segment(aes(x = -100, xend = 100, y = -18.214, yend = -18.214)) +
geom_segment(aes(x = -100, xend = 100, y = -6.071, yend = -6.071)) +
geom_segment(aes(x = -100, xend = 100, y = 30.357, yend = 30.357)) +
geom_segment(aes(x = -100, xend = 100, y = 18.214, yend = 18.214)) +
geom_segment(aes(x = -100, xend = 100, y = 6.071, yend = 6.071)) +
geom_segment(aes(x = -100, xend = 100, y = -42.5, yend = -42.5)) +
geom_segment(aes(x = -100, xend = 100, y = 42.5, yend = 42.5))
What I'd like to do is assign each of those points in each zone a unique zone ID (like Zone 1 through Zone 70). I can probably write a massive ifelse
function, but that's easy to mess up. I feel like there should be an easier way to do this, but I can't figure it out.
Any help is appreciated!