Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(igraph)
- # original data as a list
- input_data = list(c(1,2,3),c(1,4,5),c(1,6),c(3),c(4,6))
- ## function that makes all pairs
- pairing <- function(x) {
- n = length(x)
- if (n<2) {
- res <- NULL
- } else {
- q <- combn(n,2)
- x2 <- x[q]
- #dim(x2) <- dim(q)
- res <- x2
- }
- return(res)
- }
- ## for each paper create all author pairs
- pairing_bypaper = lapply(input_data,pairing)
- ## remove papers that contribute no edges
- pair_noedge = sapply(pairing_bypaper,is.null)
- pair2_bypaper <- pairing_bypaper[!pair_noedge]
- ## combine all 'subgraphs'
- pair_all <- do.call('c',pair2_bypaper)
- ## how many authors are there?
- n.authors <- length(unique(pair_all))
- ## make a graph
- my_graph = graph(pair_all, directed = FALSE)
- ## plot
- plot(my_graph)
- plot(my_graph, vertex.label.cex = 0.8, edge.width = E(my_graph)$weight)
- degree(my_graph)
- [1] 5 2 2 3 2 2
- ## size
- V(my_graph)$vertex_degree <- degree(my_graph)
- plot(my_graph,
- vertex.label.cex = 0.8,
- edge.width = E(my_graph)$weight,
- vertex.size = V(my_graph)$vertex_degree #add this
- )
- scale_factor <- 4
- plot(my_graph,
- vertex.label.cex = 0.8,
- edge.width = E(my_graph)$weight,
- vertex.size = V(my_graph)$vertex_degree * scale_factor
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement