Skip to contents

This function transforms an igraph graph object into a networkD3 interactive visualization. It allows customization of titles, node colors, missing link colors, and additional HTML code insertion.

Usage

get_networkd3_from_igraph(
  graph_igraph,
  title_h1 = "networkD3",
  subtitle_h2 = NULL,
  endnotes_h3 = NULL,
  colors_for_nodes = c("green", "grey", "black", "red"),
  color_outdeg_instead_of_indeg = F,
  color_for_na_link = colors_for_nodes[[1]],
  charge = -200,
  ...
)

Arguments

graph_igraph

An igraph object representing the network.

title_h1

character. The main title (HTML <h1>) displayed above the graph. Default is "networkD3".

subtitle_h2

character (optional). The subtitle (HTML <h2>) displayed below the main title. Default is NULL (no subtitle).

endnotes_h3

character (optional). A description or note (HTML <h3>) displayed after the network. Default is NULL (no text).

colors_for_nodes

character vector. Specifies colors for nodes based on their degree and also number of separation the func' will try to realize (based on indegrees or outdegrees). Default is c("green", "grey", "black", "red").

color_outdeg_instead_of_indeg

logical. If TRUE, node colors are assigned based on out-degree instead of in-degree. Default is FALSE.

character. Color assigned to links when data is missing. Default is the 1st color of colors_for_node ("green").

charge

integer, default = -200 Numeric value indicating either the strength of the node repulsion (negative value) or attraction (positive value). Passed to networkD3::forceNetwork.

...

optional parameter passed to networkD3::forceNetwork

Value

A "forceNetwork" & "htmlwidget" object, i.e. a list that symbolize an html object from networkD3::forceNetwork

Examples

invisible(library(igraph))
#> 
#> Attaching package: ‘igraph’
#> The following objects are masked from ‘package:stats’:
#> 
#>     decompose, spectrum
#> The following object is masked from ‘package:base’:
#> 
#>     union
g <- make_ring(10)
get_networkd3_from_igraph(g, title_h1 = "My Network")

My Network

Colors (indegree)