# NOT RUN {
# load data
data(sim_pu_raster, sim_pu_sf, sim_pu_lines)
# create adjacency matrix using raster data
## crop raster to 9 cells
r <- crop(sim_pu_raster, c(0, 0.3, 0, 0.3))
## make adjacency matrix
am_raster <- adjacency_matrix(r)
# create adjacency matrix using polygons (sf) data
## subset 9 polygons
ply <- sim_pu_sf[c(1:2, 10:12, 20:22), ]
## make adjacency matrix
am_ply <- adjacency_matrix(ply)
# create adjacency matrix using lines (Spatial) data
## subset 9 lines
lns <- sim_pu_lines[c(1:2, 10:12, 20:22), ]
## make adjacency matrix
am_lns <- adjacency_matrix(lns)
# plot data and the adjacency matrices
# }
# NOT RUN {
par(mfrow = c(4,2))
## plot raster and adjacency matrix
plot(r, main = "raster", axes = FALSE, box = FALSE)
plot(raster(as.matrix(am_raster)), main = "adjacency matrix", axes = FALSE,
box = FALSE)
## plot polygons (sf) and adjacency matrix
plot(r, main = "polygons (sf)", axes = FALSE, box = FALSE)
plot(raster(as.matrix(am_ply)), main = "adjacency matrix", axes = FALSE,
box = FALSE)
## plot lines (Spatial) and adjacency matrix
plot(r, main = "lines (Spatial)", axes = FALSE, box = FALSE)
plot(raster(as.matrix(am_lns)), main = "adjacency matrix", axes = FALSE,
box = FALSE)
# }
Run the code above in your browser using DataLab