Skip to content

Instantly share code, notes, and snippets.

@agila5
Created October 14, 2024 12:14
Show Gist options
  • Save agila5/c02238e5849e50ca366e27c1d7bfee22 to your computer and use it in GitHub Desktop.
Save agila5/c02238e5849e50ca366e27c1d7bfee22 to your computer and use it in GitHub Desktop.
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment