# NOT RUN {
library(ggplot2)
library(dplyr)
library(stringr)
library(sf)
library(sfheaders)
library(tibble)
# Create fold information sf object.
SpatialBlock_ex <-
tibble(
# Study region boundary
x = c(0, 0, 5, 5),
y = c(0, 5, 5, 0)
) %>%
# Convert to sf object
sf_polygon() %>%
mutate(folds = "1")
# Plot example data. Observe for comp_dist = 1.5, there are 6 focal vs comp pairs:
# 1. focal 1 vs comp 2
# 2. focal 2 vs comp 1
# 3. focal 2 vs comp 3
# 4. focal 3 vs comp 2
# 5. focal 4 vs comp 5
# 6. focal 5 vs comp 4
ggplot() +
geom_sf(data = SpatialBlock_ex, fill = "transparent") +
geom_sf_label(data = growth_toy, aes(label = ID))
# Return corresponding data frame
growth_toy %>%
mutate(basal_area = 0.0001 * pi * (dbh1 / 2)^2) %>%
create_focal_vs_comp(comp_dist = 1.5, blocks = SpatialBlock_ex, id = "ID",
comp_x_var = "basal_area")
# Load in growth_df with spatial data
# See ?growth_ex for attaching spatial data to growth_df
data(growth_spatial_ex)
# Load in blocks
data(blocks_ex)
focal_vs_comp_ex <- growth_spatial_ex %>%
mutate(basal_area = 0.0001 * pi * (dbh1 / 2)^2) %>%
create_focal_vs_comp(comp_dist = 1, blocks = blocks_ex, id = "ID",
comp_x_var = "basal_area")
# }
Run the code above in your browser using DataLab