Last active
March 13, 2017 08:32
-
-
Save edsu/123b255524707cc8a3abccd5f7b81af2 to your computer and use it in GitHub Desktop.
Some R code from Ernesto for generating a graph visualization of a friend-of-a-friend network that was created with https://github.com/DocNow/twarc/blob/master/utils/foaf.py
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
library(igraph) | |
##READ FILE | |
setwd("E:/JSON FILES/MacriCongreso") | |
my.file<-"clarinfriends.json" | |
my.friends <- read.csv(my.file, colClasses = "character") | |
##EDGE LIST | |
data<-cbind(my.friends[,2],my.friends[,1]) | |
##LOAD NET | |
all.net <- graph.empty() | |
all.net <- add.vertices(all.net, length(unique(c(data))),name=as.character(unique(c(data)))) | |
all.net <- add.edges(all.net, t(data)) | |
##MEASURE OUT DEGREE AND IN-DEGREE | |
outd<-degree(all.net, mode="out") | |
ind<-degree(all.net, mode="in") | |
##SELECT NODES THAT HAVE MORE THAN 1 OR 2 OUTDEGREE | |
select.edges<-which(outd>2 | ind>=1) | |
net <- induced.subgraph(graph=all.net,vids=select.edges) | |
##LAYOUT AND COMMUNITY DETECTION | |
system.time(l <- layout_with_fr(net, grid = c("nogrid"))) | |
my.com.fast <- walktrap.community(net) | |
save.image("Friends of Clarin Net.RData") | |
## PLOT AS PDF | |
pdf(file = "Friends Network Plot.pdf", 40, 40, pointsize=12, compress=FALSE) | |
plot.igraph(net,vertex.label=NA, layout=l, vertex.size=log(degree(net, mode="in")+1), vertex.color=my.com.fast$membership, edge.color=gray(.9), vertex.frame.color=my.com.fast$membership, edge.curved=TRUE) | |
dev.off() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment