Last active
August 29, 2015 14:18
-
-
Save dashalom/9c5110efc93947f6aa10 to your computer and use it in GitHub Desktop.
Closest amphitheaters and cities to Rome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load libraries | |
library(curl) | |
library(igraph) | |
library(rgeos) | |
library(rgdal) | |
library(maptools) | |
library(sp) | |
library(ggplot2) | |
library(leaflet) | |
#load data sets of nodes and edges | |
orbis_edges <-read.csv(curl("https://stacks.stanford.edu/file/druid:mn425tz9757/orbis_edges_0514.csv"),head=TRUE) | |
orbis_nodes<-read.csv(curl("https://stacks.stanford.edu/file/druid:mn425tz9757/orbis_nodes_0514.csv"),head=TRUE) | |
#subset two columns from orbis_nodes. | |
temp.df <- orbis_nodes[,c("id","label")] | |
#create the network | |
o.nw <- graph.data.frame(orbis_edges, vertices=temp.df, directed=TRUE) | |
#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) | |
# divide into equal fiftieths (or choose another number) | |
# first print it | |
quantile(V(o.nw)$torome, probs = 1:50/50) | |
# now keep it for future use | |
quantile(V(o.nw)$torome, probs = 1:50/50) -> breaks | |
# subgraph by various values of torome | |
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 | |
) | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment