[R-sig-Geo] Plotting part of the nb object

Grzegorz Sapijaszko grzegorz @end|ng |rom @@p|j@@zko@net
Tue Dec 26 22:42:59 CET 2023


On 12/25/23 08:19, Xiang Ye via R-sig-Geo wrote:
> I am thinking of extracting the neighboring regions into a new sf
> object, then drawing the neighborhood network of the new sf object, but
> it won't give me what I want: instead of a stellated-shaped ego-network,
> it still contains the redundant peripheral edges:
>
> bristol_zones[c(5, bqueen[[5]]), ] -> temp
> plot(poly2nb(temp), st_geometry(temp)) # This line generates unwanted
> peripheral edges
I do believe the plot is correct. That's because "South Gloucestershire 
005" is a neighbor to "South Gloucestershire 018" and the edges are 
drawn for all neighbors in the (sub)set. Your workaround to create a 
temporary sf object first might be the best solution, as plot.nb() 
requires nb class object.

t <- poly2nb(bristol_zones)
t5 <- bristol_zones[c(5, t[[5]]), ]

t <- poly2nb(t5)

plot(1,
   xlim = c(sf::st_bbox(t5)[1], sf::st_bbox(t5)[3]),
   ylim = c(sf::st_bbox(t5)[2], sf::st_bbox(t5)[4]),
   xlab = "", ylab = ""
)
plot(t5[, c("name", "geometry")], add = TRUE)
plot.nb(t, st_geometry(t5), add = TRUE)

Regards,
Grzegorz
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list