A few examples of calculating graph distance from Rome according to http://orbis.stanford.edu . Data from http://purl.stanford.edu/mn425tz9757 .
Adapted from code and comments developed in NYU/ISAW’s “Mapping and Data Visualization” Spring 2015 seminar.
#load libraries
library(curl)
library(igraph)
# cawd is an R package of "Collected Ancient World Data"
# http://github.com/sfsheath/cawd
library(cawd)
#subsetting two columns from orbis_nodes. otherwise the NA x,y's get in the way.
temp.df <- orbis.nodes[,c("id","label")]
#setting the network
o.nw <- graph.data.frame(orbis.edges, vertices=temp.df, directed=TRUE)
# this now plot()able but it's so big that it's too messy to be useful
#finding the shortest paths referring to Roma, by expenses, and assigning to a new object
shortest.paths(o.nw,V(o.nw)[V(o.nw)$label == "Roma"], weights = E(o.nw)$expense) -> o.nw.torome
o.nw <- set.vertex.attribute(o.nw, "torome", index = V(o.nw), value = o.nw.torome)
# first print it
quantile(V(o.nw)$torome, probs = 1:50/50)
## 2% 4% 6% 8% 10% 12% 14% 16%
## 0.26878 0.43936 0.56010 0.68936 0.79270 0.88648 0.95514 1.03008
## 18% 20% 22% 24% 26% 28% 30% 32%
## 1.12586 1.21180 1.26194 1.29300 1.34206 1.37484 1.45420 1.55628
## 34% 36% 38% 40% 42% 44% 46% 48%
## 1.61572 1.67272 1.74800 1.78560 1.87202 2.04432 2.22526 2.35504
## 50% 52% 54% 56% 58% 60% 62% 64%
## 2.50250 2.72548 3.03662 3.23196 3.46152 3.66640 3.91100 4.13836
## 66% 68% 70% 72% 74% 76% 78% 80%
## 4.50230 4.97168 5.51670 5.97540 6.43634 6.82260 7.33426 7.66700
## 82% 84% 86% 88% 90% 92% 94% 96%
## 8.61508 9.40460 9.77054 10.22608 10.67420 11.16016 11.98918 13.16992
## 98% 100%
## 15.34150 22.66700
# now keep it for future use
quantile(V(o.nw)$torome, probs = 1:50/50) -> breaks
This could be turned into a trivial function but I just copy-and-paste for clarity. For now…
In all of the following examples, the V() function, which lists verteces in an igraph graph, is used to select verteces accoring to their “distance” from Rome accoring to the Orbis graph.
Note that I am just increasing the index into ‘breaks[]’.
tmp.nw <- subgraph(o.nw, v = V(o.nw)[torome <= breaks[1]])
plot(tmp.nw,
edge.arrow.size = 0,
vertex.label.cex = .6
)
tmp.nw <- subgraph(o.nw, v = V(o.nw)[torome <= breaks[2]])
plot(tmp.nw,
edge.arrow.size = 0,
vertex.label.cex = .6
)
tmp.nw <- subgraph(o.nw, v = V(o.nw)[torome <= breaks[3]])
plot(tmp.nw,
edge.arrow.size = 0,
vertex.label.cex = .6,
vertex.label.color = 'red'
)
tmp.nw <- subgraph(o.nw, v = V(o.nw)[torome <= breaks[5]])
plot(tmp.nw,
edge.arrow.size = 0,
vertex.label.cex = .6,
vertex.size = 2
)
tmp.nw <- subgraph(o.nw, v = V(o.nw)[torome <= breaks[10]])
plot(tmp.nw,
edge.arrow.size = 0,
vertex.label.cex = .6,
vertex.size = 2
)