summary.graph <- function (graph.object){ adjm <- as.matrix(get.adjacency(graph.object)) adjm[lower.tri(adjm)]=0 role1<-netcarto(adjm) role2<-role1[[1]] nModules.SA <- length(unique(role2$module)) edge<-ecount(graph.object) node<-vcount(graph.object) nodeDegree<-round((edge/node),3) connectance<-round((edge/(node^2)),3) avgpath <- round(average.path.length(graph.object),3) trans <- round(transitivity(graph.object, type = c("average")),3) wtc<-max((walktrap.community(graph.object))$membership) mod <- round(modularity(walktrap.community(graph.object)),3) top3hub<-top3Hub(graph.object)[1] top3hubv<-top3Hub(graph.object)[2] n_postiveL <- sum((E(graph.object)$weight > 0 ) * 1) n_negativeL <- sum((E(graph.object)$weight < 0 ) * 1) tabular <- data.frame(node,edge,nodeDegree,avgpath, trans, mod,connectance,wtc, nModules.SA,top3hub,top3hubv, n_postiveL, n_negativeL) return(tabular) }
library(devtools) install_github("ravinpoudel/myFunctions") library(myFunctions) library(igraph) library(rnetcarto) library(knitr)
g <- erdos.renyi.game(10, 1/10) analyse_graph <- summary.graph(g) kable(analyse_graph) plot(g)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.