#' @title Plot microRNA co-expression network.
#'
#' @description \code{createUnipartiteNet} generates an undirected microRNA co-expression netwwork with vertices assigned different colors to observe the community structure.
#'
#' @param adjm The adjacency matrix.
#' @param filename The name specified to the output igraph object and figure.
#' @param layout The layout function to apply to a graph, refer to \code{\link[igraph]{layout_}} for more detail.
#' @param Vsize Numeric, the size of the vertices.
#' @param Vcolor A vector, with entries specifying colors of vertices.
#'
#' @return A 'rda' file with the igraph object, and a 'pdf' file with the plotted graph.
#'
#' @seealso \code{\link[igraph]{igraph}} for all available layouts.
#'
#' @export createUnipartiteNet
#'
#' @examples
#' # prepare an adjacency matrix
#' set.seed(3)
#' adj.m <- matrix(sample(c(0, 1), 25, replace = TRUE), nrow = 5, ncol = 5)
#'
#' # prepare the color vector
#' color.v <- c('blue', 'blue', 'blue', 'red', 'blue')
#'
#' # generate the network
#' createUnipartiteNet(adjm = adj.m, Vcolor = color.v, filename = 'example')
createUnipartiteNet <- function(adjm, filename = NULL, layout = layout_nicely, Vsize = 7, Vcolor){
# plot adjacency matrix
net.o <- graph_from_adjacency_matrix(adjm, weighted = TRUE, diag = FALSE, mode = 'undirected')
E(net.o)$width <- E(net.o)$weight
save(net.o, file = paste0(filename, '.rda'))
# plot
pdf(paste0(filename, '.pdf'), height = 8, width = 8)
#vertex_label = c(rep('', length(uni.gene)), uni.miR)
plot.igraph(net.o, vertex.size = Vsize, vertex.size2 = Vsize, vertex.color = adjustcolor(Vcolor, 0.3), vertex.frame.color = 'grey', vertex.shape = 'circle', vertex.label = NA, vertex.label.family = 'sans', vertex.label.font = 1, vertex.label.cex = 1, vertex.label.dist = 0, vertex.label.degree = -pi/4, vertex.label.color = 'black', edge.color = adjustcolor('grey', 0.2), edge.width = 3*E(net.o)$width/max(E(net.o)$width), edge.lty = 1, edge.label = NA, edge.curved = FALSE, layout = layout, asp = 0, main = filename, margin = 0)
dev.off()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.