title | author | date | output |
---|---|---|---|
EX3 |
AdamAndDaniel |
April 28, 2016 |
html_document |
#QUESTION 1
library('igraph')
library('sna')
ga.data <- read.csv('ga_edgelist.csv', header = T)
gg <- graph.data.frame(ga.data,directed = F)
ga.data <- read.csv('ga_edgelist.csv', header=TRUE, stringsAsFactors=FALSE)
ga.vrtx <- read.csv('ga_actors.csv', header=TRUE, stringsAsFactors=FALSE)
gg <- graph.data.frame(ga.data, vertices=ga.vrtx, directed=FALSE)
betweenness(gg)
which.max(betweenness(gg))
closeness(gg)
which.max(closeness(gg))
eig <- eigen_centrality(gg)
eig$vector
which.max(eig$vector)
fc <- edge.betweenness.community(gg)
fc$modularity
which.max(fc$modularity)
memb <- membership(fc)
max(memb)
plot(gg, vertex.size=10, vertex.label=NA,vertex.color=memb, asp=FALSE)
dc <- leading.eigenvector.community(gg)
dc$modularity
which.max(dc$modularity)
membTwo <- membership(dc)
max(membTwo)
plot(gg, vertex.size=10, vertex.label=NA,vertex.color=membTwo, asp=FALSE)
#QUESTION 2 USING TWITTER DATA
load('termDocMatrix.rdata')
termDocMatrix[1:20,1:20]
termDocMatrix[termDocMatrix>=1] <- 1
termMatrix <- termDocMatrix %*% t(termDocMatrix)
termMatrix[5:10,5:10]
g <- graph.adjacency(termMatrix, weighted=T, mode = "undirected")
g <- simplify(g)
V(g)$label <- V(g)$name
V(g)$degree <- degree(g)
Set the label size of vertices based on their degrees , label.cex - The font size for vertex labels.
V(g)$label.cex <- 2.2 * V(g)$degree / max(V(g)$degree) + .2
V(g)$label.color <- rgb(0, 0, .2, .8)
V(g)$frame.color <- NA
E(g)$weight
egam <- (log(E(g)$weight)+.4) / max(log(E(g)$weight)+.4)
E(g)$color <- rgb(.5, .5, 0, egam)
E(g)$width <- egam
plot(g, layout=layout1)
set.seed(3952)
layout1 <- layout.fruchterman.reingold(g)
plot(g, layout=layout1)
betweenness(g)
which.max(betweenness(g))
closeness(g)
which.max(closeness(g))
eig <- eigen_centrality(g)
eig$vector
which.max(eig$vector)
edge.betweenness.community(g)
fc <- edge.betweenness.community(g)
fc$modularity
which.max(fc$modularity)
memb <- membership(fc)
max(memb)
plot(g, vertex.size=10, vertex.label=NA,vertex.color=memb, asp=FALSE)
leading.eigenvector.community(g)
dc <- leading.eigenvector.community(g)
dc$modularity
which.max(dc$modularity)
membTwo <- membership(dc)
max(membTwo)
plot(g, vertex.size=10, vertex.label=NA,vertex.color=membTwo, asp=FALSE)