require(igraph) require(graphstats) require(gridExtra) require(ggplot2)
# define this function load.data <- function(dat) { e <- new.env() name <- data(list=dat, envir = e)[1] e[[name[[1]]]] } make_plots <- function(datname, title, src.name, tgt.name, attr.code, src.attr.name, tgt.attr.name, wt, edge.xfm) { # Adjacency Matrix g <- load.data(datname) adj.plot <- gs.plot.plot_adjacency(g, title=title, edge.attr = wt, src.label=src.name, tgt.label=tgt.name, edge.xfm=edge.xfm) # Degree Sequence gr.degseq.in <- strength(g, mode="in") gr.degseq.out <- strength(g, mode="out") if (isTRUE(all.equal(as.numeric(gr.degseq.in), as.numeric(gr.degseq.out)))) { gr.deg.dat <- data.frame(vertex=names(V(g)), degree=gr.degseq.in, Direction="undirected") } else { gr.deg.dat <- rbind(data.frame(vertex=names(V(g)), degree=gr.degseq.in, Direction="in"), data.frame(vertex=names(V(g)), degree=gr.degseq.out, Direction="out")) } deg.plot <- ggplot(gr.deg.dat, aes(x=degree, group=Direction, fill=Direction)) + geom_density(alpha=0.2) + xlab("Vertex Degree") + ylab("Probability") + ggtitle(title) + theme_bw() # SBM gr.sbm <- gs.sbm.fit(g, community.attribute=attr.code, edge.attr="weight") sbm.plot <- gs.plot.plot_adjacency(gr.sbm, title=title, src.label=src.attr.name, tgt.label=tgt.attr.name, vertex.label=TRUE, edge.attr="weight") return(list(adj.plot=adj.plot, deg.plot=deg.plot, sbm.plot=sbm.plot)) }
mouse.duke <- make_plots("mouse.duke", "Mouse dMRI", "Source ROI", "Target ROI", "level1", "Source Region", "Target Region", "weight", edge.xfm="log10")
#mouse.allan.ipsi <- make_plots("mouse.allan.ipsi", "Mouse, Green Protein, Ipsilateral", "Source ROI", "Target ROI", "region", # "Source Region", "Target Region", "weight", edge.xfm="log10")
#mouse.allan.contra <- make_plots("mouse.allan.contra", "Mouse, Green Protein, Contralateral", "Source ROI", "Target ROI", "region", # "Source Region", "Target Region", "weight", edge.xfm="log10")
#grid.arrange(mouse.duke$adj.plot, mouse.allan$adj.plot, ncol=2) mouse.duke$adj.plot
#grid.arrange(mouse.duke$deg.plot, mouse.allan$deg.plot, ncol=2) mouse.duke$deg.plot
#grid.arrange(mouse.duke$sbm.plot, mouse.allan$sbm.plot, ncol=2) mouse.duke$sbm.plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.