Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(RCurl)
- library(igraph)
- library(compiler)
- su<-function(x) return(sort(unique(x)))
- su<-cmpfun(su)
- read.sstab<-function(theurl, ...){ #Function to read in a data table from online
- #_theurl_ refers to the location of the data
- #_..._ are parameters passed onto read.table
- require(RCurl)
- outtab<-getURL(theurl, ssl.verifypeer=FALSE)
- outtab<-textConnection(outtab)
- outtab<-read.table(outtab, sep="\t", ...)
- return(outtab)
- }
- #Import the data
- wikidat<-read.sstab("http://pastebin.com/raw.php?i=UVmTznBj", header=TRUE, skip=6)
- #Convert the data to igraph
- wikidat<-graph.data.frame(wikidat, directed=TRUE)
- V(wikidat)$comp.w<-clusters(wikidat, mode="weak")$membership
- V(wikidat)$comp.s<-clusters(wikidat, mode="strong")$membership
- #I'll need to recalculate these scores
- wikidat.eb<-read.sstab("http://pastebin.com/raw.php?i=w4fTuUje", header=TRUE) #Read in edge betweenness scores
- wikidat<-igraph::set.edge.attribute(wikidat, "edge.betw", value=wikidat.eb$Edge.Betw) #Set edge betweenness as an edge attribute
- wikidat<-igraph::set.edge.attribute(wikidat, "max.minus.edge.betw", value=wikidat.eb$max.minus.Edge.Betw) #Set max(edge betweenness) - edge betweenness as an attribute
- rm(wikidat.eb)
- download.file("http://pastebin.com/raw.php?i=a7sF1V75", "snaspb2013.net") #Download data
- snaspb2013<-read.graph("snaspb2013.net", "pajek") #Create igraph object
- file.remove("snaspb2013.net") #Remove downloaded item
- V(snaspb2013)$indegree<-degree(snaspb2013, mode="in")
- V(snaspb2013)$outdegree<-degree(snaspb2013, mode="out")
- V(snaspb2013)$totaldegree<-degree(snaspb2013, mode="total")
- V(snaspb2013)$loc.trans<-transitivity(snaspb2013, "local")
- V(snaspb2013)$betw<-betweenness(snaspb2013)
- E(snaspb2013)$eb<-edge.betweenness(snaspb2013)
- V(snaspb2013)$comp.w<-clusters(snaspb2013, mode="weak")$membership
- V(snaspb2013)$comp.s<-clusters(snaspb2013, mode="strong")$membership
- V(snaspb2013)$closeness<-closeness(snaspb2013)
- V(snaspb2013)$evcent<-evcent(snaspb2013)$vector
- V(snaspb2013)$kc.undir<-graph.coreness(as.undirected(snaspb2013, mode="collapse"))
- snaspb2013.sg.members<-which(V(snaspb2013)$comp.w == which.max(clusters(snaspb2013, mode="weak")$csize))
- snaspb2013.sg<-induced.subgraph(snaspb2013, snaspb2013.sg.members)
- snaspb2013.comms<-multilevel.community(as.undirected(snaspb2013.sg, mode="collapse"))
- snaspb2013.comms$modularity
- V(snaspb2013.sg)$comms<-snaspb2013.comms$membership
- names(snaspb2013.comms$membership)<-V(snaspb2013.sg)$id
- sort(snaspb2013.comms$membership)
- snaspb2013.comms.w<-multilevel.community(as.undirected(snaspb2013.sg, mode="collapse"), weights=max(E(snaspb2013.sg)$eb)-E(snaspb2013.sg)$eb)
- snaspb2013.comms.w$modularity
- V(snaspb2013.sg)$comms.w<-snaspb2013.comms.w$membership
- names(snaspb2013.comms.w$membership)<-V(snaspb2013.sg)$id
- sort(snaspb2013.comms.w$membership)
- snaspb.layout<-layout.fruchterman.reingold(snaspb2013, params=list(niter=5000, area=vcount(snaspb2013)^3))
- V(snaspb2013)$x<-snaspb.layout[,1]
- V(snaspb2013)$y<-snaspb.layout[,2]
- rm(snaspb.layout)
- snaspb2013.sg.layout<-layout.fruchterman.reingold(snaspb2013.sg, params=list(niter=5000, area=vcount(snaspb2013.sg)^3))
- V(snaspb2013.sg)$x<-snaspb2013.sg.layout[,1]
- V(snaspb2013.sg)$y<-snaspb2013.sg.layout[,2]
- rm(snaspb2013.sg.layout)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement