-1

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)

PCK1992
  • 213
  • 1
  • 14
  • Yes, follow the solution in the question you reference. To avoid plotting the map, remove the references to the Cario package and function. You may need to adjust the value for the "dpi" variable, the plot colors, and adjust the x and y limits. – Dave2e Jul 07 '20 at 19:51
  • 1
    Does this answer your question? [Using geo-coordinates as vertex coordinates in the igraph r-package](https://stackoverflow.com/questions/30647537/using-geo-coordinates-as-vertex-coordinates-in-the-igraph-r-package) – Dave2e Jul 07 '20 at 19:53
  • Thanks for the suggestion but unfortunately the solution was for igraph. I did manage to do something very similar with statnet though. I appreciate it! – PCK1992 Jul 08 '20 at 00:18

1 Answers1

1

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)
)
PCK1992
  • 213
  • 1
  • 14