R/plot_network.R

Defines functions plot_network

Documented in plot_network

#' Generation of an interactive mclean network
#'
#' Visualize a network using D3.js at specific threshold
#'
#' @param output mclean list output.
#' @param Group character string specifying the group of each node in the \code{Nodes} data frame.
#'
#' @author Daniel Alcaide, \email{daniel.alcaide@@esat.kuleuven.be}
#' @references Alcaide D, Aerts J. (2018) MCLEAN: Multilevel Clustering Exploration As Network. PeerJ Computer Science 4:e145 \url{https://doi.org/10.7717/peerj-cs.145}
#'
#' @examples
#' data("synthetic_distances")
#' output = mclean(distance_matrix = synthetic_distances, threshold = 187, method = "single")
#' plot_network(output)
#'
#' @export
plot_network = function(output, Group = "infomap",...){

  radiusNode = JS(paste("var scale = d3.scaleLinear().domain([",
                        min(output$node$size),
                        ",",
                        max(output$node$size),
                        "]).range([4,30]); scale(d.nodesize);", sep=""))

  if(  "x" %in% colnames(output$nodes) & "y" %in% colnames(output$nodes) ) {

    networkFix(Links = output$links,
                         Nodes = output$nodes,
                         Source = "source",
                         Target = "target",
                         Component = "components",
                         NodeID = "name",
                         Nodesize = "size",
                         opacity = 0.8,
                         Group = Group,
                         colourScale = JS("d3.scaleOrdinal(d3.schemeCategory10);"),
                         legend = FALSE,
                         opacityNoHover = 0,
                         fontSize = 14, radiusCalculation = radiusNode,...)



  } else {

    networkForceDirected(Links = output$links,
                         Nodes = output$nodes,
                         Source = "source",
                         Target = "target",
                         Component = "components",
                         NodeID = "name",
                         Nodesize = "size",
                         opacity = 0.8,
                         Group = Group,
                         colourScale = JS("d3.scaleOrdinal(d3.schemeCategory10);"),
                         legend = FALSE,
                         opacityNoHover = 0,
                         fontSize = 14, radiusCalculation = radiusNode,...)

  }

}
danielalcaide/mclean documentation built on May 28, 2019, 7:51 p.m.