Is it possible to plot a network object using the coordinates as the layout for nodes? I don't want to plot them on a map but just to show the physical distance between nodes based on their lat/long position.
Data borrowed from: Using geo-coordinates as vertex coordinates in the igraph r-package
library(statnet)
df <- data.frame("from" = c("Bob", "Klaus", "Edith", "Liu"),
"to" = c("Edith", "Edith", "Bob", "Klaus"))
meta <- data.frame("name" = c("Bob", "Klaus", "Edith", "Liu"),
"lon" = c(-74.00714, 13.37699, 2.34120, 116.40708),
"lat" = c(40.71455, 52.51607, 48.85693, 39.90469))
net<-as.network(df)
set.vertex.attribute(net, names(meta), meta)
It was much more trivial than I thought! The solution is very similar to the one in igraph.
In addition to the above code, the following line of code will plot the network according to the coordinates:
plot(net , coord = meta[,c(2,3)])
This works fairly well for networks with large distances. If the nodes of your network are fairly close you might need to specify proper xlim
and ylim
parameters to get a good representation. For this example, it is not necessary but this is what it would look like (which was necessary in my case).
plot(net ,
coord = meta[,c(2,3)],
ylim = c(-80,116),
xlim = c(39,54)
)