suppressPackageStartupMessages({library(spatstat)})
vertices <- ppp(
c(0, 1, 2, 1, 1),
c(0, 1, 0, -1, 0),
window = owin(c(-1, 3), c(-2, 2))
)
#matrice di adiacenza
adjacency_matrix <- matrix(c(
0, 1, 0, 1, 1,
1, 0, 1, 0, 1,
0, 1, 0, 1, 1,
1, 0, 1, 0, 1,
1, 1, 1, 1, 0
), nrow = 5, ncol = 5
)
adjacency_matrix <- adjacency_matrix == 1
#creo rete lineare
rete <- linnet(vertices, adjacency_matrix)
#definisco il point pattern
punti <- ppp(x = c(1,0.5), y = c(0.5,0.5), window = vertices$window)
point_pattern <- lpp(punti, rete)
#plot
plot(vertices$window, main = "Point Pattern su rete", lwd = 2)
plot(rete, add = TRUE, col = "red", lwd = 2)
points(punti, col = "blue", pch = 16, cex = 1.5)
axis(1, col.axis = "black", las = 1) # Asse x
axis(2, col.axis = "black", las = 1) # Asse y
dist_fun = distfun(point_pattern)
plot(dist_fun)
points(punti, col = "blue", pch = 16, cex = 1.5)
axis(1, col.axis = "black", las = 1) # Asse x
axis(2, col.axis = "black", las = 1) # Asse y
Created on 2024-10-14 with reprex v2.0.2