library(igraph)
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
rm(list = ls()) ## clears global environment
cat("\014") ## clears screen
setwd("C:/users/evazquez/Downloads/netscix2016")
nodes<-read.csv("Dataset1-Media-Example-NODES.csv", header=T, as.is=T)
links<-read.csv("Dataset1-Media-Example-EDGES.csv", header=T, as.is=T)
head(nodes)
## id media media.type type.label audience.size
## 1 p520736 Proyecto 1 Proyecto 23.299528
## 2 p496048 Proyecto 1 Proyecto 6.747076
## 3 p473856 Proyecto 1 Proyecto 1.000000
## 4 p496026 Proyecto 1 Proyecto 5.140315
## 5 p468161 Proyecto 1 Proyecto 1.000000
## 6 p426296 Proyecto 1 Proyecto 3.098989
head(links)
## from to weight type
## 1 p520736 e36 10 proposal
## 2 p496048 e30 10 proposal
## 3 p473856 e30 10 proposal
## 4 p496026 e32 20 proposal
## 5 p468161 e67 20 proposal
## 6 p426296 e45 20 proposal
nrow(nodes); length(unique(nodes$id))
## [1] 151
## [1] 151
nrow(links); nrow(unique(links[,c("from", "to")]))
## [1] 324
## [1] 289
links <- aggregate(links[,3], links[,-3], sum)
links <- links[order(links$from, links$to),]
colnames(links)[4] <- "weight"
rownames(links) <- NULL
net <- graph_from_data_frame(d=links, vertices=nodes, directed=F)
class(net)
## [1] "igraph"
plot(net, vertex.label=NA,edge.arrow.size=.4)

net <- simplify(net, remove.multiple = F, remove.loops = T)
colrs <- c("gray50", "tomato")
V(net)$color <- colrs[V(net)$media.type]
V(net)$size <- V(net)$audience.size*0.7
V(net)$label.color <- "black"
V(net)$label <- NA
E(net)$width <- E(net)$weight/6
E(net)$arrow.size <- .2
E(net)$edge.color <- "gray70"
E(net)$width <- 1+E(net)$weight/12
plot(net, edge.color="orange", vertex.color="gray10")

plot(net)
legend(x=-1.5, y=-1.1, c("Proyecto","Empresa"),pch=21,col="#777777",pt.bg=colrs,pt.cex=2,cex=.8,bty="n",ncol=1)

# tkid <- tkplot(net) #tkid is the id of the tkplot that will open
# l <- tkplot.getcoords(tkid) # grab the coordinates from tkplot
# tk_close(tkid, window.close = T)
# plot(net, layout=l)
ceb <- cluster_edge_betweenness(net)
plot(ceb, net)

transitivity(net)
## [1] 0.6024974