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)) }
human.dmri.tissue <- make_plots("human.dmri", "Human dMRI", "Source ROI", "Target ROI", "tissue", "Tissue Type", "Tissue Type", "weight", edge.xfm="log10") human.dmri.hem <- make_plots("human.dmri", "Human dMRI", "Source ROI", "Target ROI", "tissue", "Hemisphere", "Hemisphere", "weight", edge.xfm="log10")
human.fmri.hem <- make_plots("human.fmri", "Human fMRI", "Source ROI", "Target ROI", "tissue", "Hemisphere", "Hemisphere", "weight", edge.xfm=FALSE) human.fmri.tissue <- make_plots("human.fmri", "Human fMRI", "Source ROI", "Target ROI", "tissue", "Hemisphere", "Hemisphere", "weight", edge.xfm=FALSE)
grid.arrange(human.dmri.hem$adj.plot, human.fmri.hem$adj.plot, ncol=2)
grid.arrange(human.dmri.hem$deg.plot, human.fmri.hem$deg.plot, ncol=2)
grid.arrange(human.dmri.hem$sbm.plot, human.fmri.hem$sbm.plot, ncol=2) grid.arrange(human.dmri.tissue$sbm.plot, human.fmri.tissue$sbm.plot, ncol=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.