top <- function(v,k){ ord <- rev(order(v)); sel <- ord[1:k] S <- data.frame(name=names(v[sel]),value=as.vector(v[sel])) return(S) }
> wdir <- "C:/Users/batagelj/Documents/papers/2017/Moscow/Rnet/test" > setwd(wdir) > library(igraph) # delete *network and empty line before *vertices > T <- read.graph("./nets/eatRS.net",format="pajek") > vcount(T) [1] 23219 > ecount(T) [1] 325624 > source("igraph+.R") > SR <- graph.reverse(T) > SR$indeg <- degree(SR,mode="in") > top(SR$indeg,10) name value 1 ME 1074 2 MAN 1046 3 GOOD 861 4 SEX 828 5 NO 780 6 MONEY 743 7 YES 718 8 WORK 672 9 NOTHING 672 10 FOOD 665 > SR$windeg <- strength(SR,mode="in") > max(SR$windeg) [1] 4387 > top(SR$windeg,20) > SR$awindeg <- SR$windeg/SR$indeg > SR$awindeg[is.nan(SR$awindeg)] <- 0 > top(SR$awindeg,20)
The names and types of node shapes in Pajek (“box”,”ellipse”, “triangle”, “diamond”, …) and igraph (“square”, “circle”, “pie”, …) are different. Besides this in Pajek description holds the rule that missing shape indicates the current shape in the sequence. Sometimes we can transform the Pajek's description into igraph's description as follows
> R <- read.graph("./nets/class.net",format="pajek") > vertex_attr(R)$shape [1] "box" "" "ellipse" "" "" "" "" [8] "" "" "" "box" "ellipse" "box" "" [15] "" > sh <- "ellipse" > for(i in 1:vcount(R)) + if(V(R)$shape[i]=="") V(R)$shape[i] <- sh else sh <- V(R)$shape[i] > V(R)$shape [1] "box" "box" "ellipse" "ellipse" "ellipse" "ellipse" "ellipse" [8] "ellipse" "ellipse" "ellipse" "box" "ellipse" "box" "box" [15] "box" > V(R)$shape[V(R)$shape=="box"] <- "square" > V(R)$shape[V(R)$shape=="ellipse"] <- "circle" > V(R)$shape [1] "square" "square" "circle" "circle" "circle" "circle" "circle" "circle" [9] "circle" "circle" "square" "circle" "square" "square" "square" > plot(R)
The other option is that we forget about the shapes information
> vertex_attr(R)$shape <- NULL
> library(igraph); source("igraph+.R") > SaK <- read.graph("./nets/SaKtrade.net",format="pajek") > SaK IGRAPH e1d9b99 UNW- 118 2631 -- + attr: id (v/c), name (v/c), weight (e/n) + edges from e1d9b99 (vertex names): [1] usa--sen usa--jor usa--yem usa--kod usa--lao can--bol can--alb can--eth + ... omitted several edges > V(SaK)$sc <- read_Pajek_clu("./nets/SaKtrade.clu",skip=7) > col <- c("red","green","orange","blue","green","magenta","grey","black") > V(SaK)$color <- col[V(SaK)$sc] > Af <- extract_clusters(SaK,"sc",c(6)) > plot(Af) > B <- interlinks(SaK,"sc",3,4,col1="yellow",col2="cyan") > plot(B)
> R <- read.graph("./nets/class.net",format="pajek") > vertex_attr(R)$shape <- NULL > V(R)$deg <- degree(R) > Cut <- vertex_cut(R,"deg",8) > plot(Cut,vertex.size=V(Cut)$deg*3) > E(R)$rnd <- sample(1:10,ecount(R),replace=TRUE) > Ec <- edge_cut(R,"rnd",9) > plot(Ec,edge.width=E(Ec)$rnd)