# NOT RUN {
library(tibble)
library(sfheaders)
library(ggplot2)
# Example square region to be buffered
region <- tibble(
x = c(0, 0, 1, 1),
y = c(0, 1, 1, 0)
) %>%
sf_polygon()
# Example points
study_points <- tibble(
x = runif(50),
y = runif(50)
) %>%
sf_point()
# Size of buffer
size <- 0.05
# Identify whether points are within size of boundary
study_points <- study_points %>%
add_buffer_variable(direction = "in", size = size, region = region)
# Plot study points coded by whether they are within size of boundary
p <- ggplot() +
geom_sf(data = region, fill = "transparent") +
geom_sf(data = study_points, aes(col = buffer))
p
# Additionally, show buffer boundary in red
buffer_boundary <- region %>%
compute_buffer_region(direction = "in", size = size)
p +
geom_sf(data = buffer_boundary, col = "red", fill = "transparent")
# }
Run the code above in your browser using DataLab