Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. library(igraph)
  2.  
  3. # original data as a list
  4. input_data = list(c(1,2,3),c(1,4,5),c(1,6),c(3),c(4,6))
  5.  
  6. ## function that makes all pairs
  7. pairing <- function(x) {
  8. n = length(x)
  9. if (n<2) {
  10. res <- NULL
  11. } else {
  12. q <- combn(n,2)
  13. x2 <- x[q]
  14. #dim(x2) <- dim(q)
  15. res <- x2
  16. }
  17. return(res)
  18. }
  19.  
  20. ## for each paper create all author pairs
  21. pairing_bypaper = lapply(input_data,pairing)
  22.  
  23. ## remove papers that contribute no edges
  24. pair_noedge = sapply(pairing_bypaper,is.null)
  25. pair2_bypaper <- pairing_bypaper[!pair_noedge]
  26.  
  27. ## combine all 'subgraphs'
  28. pair_all <- do.call('c',pair2_bypaper)
  29.  
  30. ## how many authors are there?
  31. n.authors <- length(unique(pair_all))
  32.  
  33. ## make a graph
  34. my_graph = graph(pair_all, directed = FALSE)
  35.  
  36. ## plot
  37. plot(my_graph)
  38.  
  39. plot(my_graph, vertex.label.cex = 0.8, edge.width = E(my_graph)$weight)
  40.  
  41. degree(my_graph)
  42. [1] 5 2 2 3 2 2
  43.  
  44. ## size
  45. V(my_graph)$vertex_degree <- degree(my_graph)
  46.  
  47. plot(my_graph,
  48. vertex.label.cex = 0.8,
  49. edge.width = E(my_graph)$weight,
  50. vertex.size = V(my_graph)$vertex_degree #add this
  51. )
  52.  
  53. scale_factor <- 4
  54. plot(my_graph,
  55. vertex.label.cex = 0.8,
  56. edge.width = E(my_graph)$weight,
  57. vertex.size = V(my_graph)$vertex_degree * scale_factor
  58. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement