Created
April 1, 2015 13:55
-
-
Save marsimaria/760f9fb92da3a5c060f4 to your computer and use it in GitHub Desktop.
Network Analysis
This file contains hidden or 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
| library(igraph) | |
| library(plyr) | |
| # load files into tables | |
| orb.edge <- read.csv("/Users/mariafang/Desktop/NYU/2_AncientData/Week9 Network/orbis_edges_0514.csv") | |
| orb.node <- read.csv("/users/mariafang/Desktop/NYU/2_AncientData/Week9 Network/orbis_nodes_0514.csv") | |
| # merge tables in two | |
| orb.tb1 <- merge(orb.edge, orb.node, by.x="source", by.y="id") | |
| orb.tb2 <- merge(orb.edge, orb.node, by.x="target", by.y="id") | |
| # rename orb.tb2 label column | |
| colnames(orb.tb2)[colnames(orb.tb2)=="label"] <- "label2" | |
| # merge main table | |
| orbs.test <- merge(orb.tb1, orb.tb2, by="row.names") | |
| # subset labels | |
| orb.labels <- subset(orbs.test, select=c(label, label2)) | |
| # convert to graph | |
| orbGraph <- graph.data.frame(orb.labels, directed=F) | |
| V(orbGraph) | |
| E(orbGraph) | |
| degree(orbGraph) | |
| vertex(orbGraph) | |
| V(orbGraph)$size<-degree(orbGraph)/10 | |
| E(orbGraph)$size<-vertex(orbGraph)*10 | |
| # plot 1 | |
| plot(orbGraph) | |
| # plot 2 | |
| plot(orbGraph, layout=layout.fruchterman.reingold, vertex.label.dist=0.5, vertex.frame.color='black', vertex.label.color='blue', vertex.label.font=1, vertex.label=V(orbGraph)$name, vertex.label.cex=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment