I'm trying to convert the nodes of a graphml file to an sf object in R. It works until I create the sfc object. Once I've added the attributes, R is no longer able to plot or do any operation with it.
library(igraph)
library(sf)
#read the graph
gi <- read.graph(
"https://jospueyo.github.io/root/girona.graphml",
format = "graphml")
#Extract coordinates and create id vector
x <- as.numeric(V(gi)$x)
y <- as.numeric(V(gi)$y)
id <- as.data.frame(seq(1:length(V(gi))))
#convert to sf object
nodes <- st_multipoint(cbind(x,y))
nodes <- st_sfc(nodes, crs=4326)
nodes <- st_sf(id, geometry = nodes)
#here it crashes
plot(st_geometry(nodes))
I tried with different graphs, obtained by different methods, and I got the same result.
Thank you.