Force Network
A Force network is also known as node-link diagram though it is useful for visualizing networks with nodes and edges which are connected by forces. Force network provides wonderful animations for understanding the network’s data element and also allows us to tweak the data in a repulsive and attractive manner.
Syntax:
forceNetwork(Links, Nodes, Source, Target, Value, NodeID, Nodesize, Group,height = NULL, width = NULL, colourScale = JS(“d3.scaleOrdinal(d3.schemeCategory20);”), fontSize = 7, fontFamily = “serif”, linkDistance = 50, linkWidth = JS(“function(d) { return Math.sqrt(d.value); }”), radiusCalculation = JS(” Math.sqrt(d.nodesize)+6″), charge = -30,linkColour = “#666”, opacity = 0.6, zoom = FALSE, legend = FALSE, arrows = FALSE, bounded = FALSE, opacityNoHover = 0,clickAction = NULL)
Arguments:
- Links – A data frame object with the links between the nodes. It should include the
Source
andTarget
for each link. An optionalValue
variable can be included to specify how close the nodes are to one another. - Nodes – A data frame containing the node id and properties of the nodes. If no ID is specified then the nodes must be in the same order as the Source variable column in the
Links
data frame. - Source – Character string naming the network source variable in the
Links
data frame. - Target – Character string naming the network target variable in the
Links
data frame. - Value – Character string naming the variable in the
Links
data frame for the links’ width. - NodeID – Character string specifying the node IDs in the
Nodes
data frame. - Nodesize – Character string specifying the column in the
Nodes
data frame with some value to vary the node radii with. See alsoradiusCalculation
. - Group – Character string defining the group of each node in the
Nodes
data frame. - height – Numeric height for the network graph’s frame area in pixels.
- width – Numeric width for the network graph’s frame area in pixels.
- colourScale – Character string defining the categorical color scale for the nodes.
- font Size – Numeric font size in pixels for the node text labels.
- font Family – Font family for the node text labels. e indicating either the strength of the node repulsion (negative value) or attraction (positive value).
- linkColour – Character vector specifying the color you want the link lines to be.
- opacity – The numeric value of the proportion opaque you would like the graph elements to be.
- zoom – Logical value ( ‘TRUE’ – enable, ‘FALSE’ – disable ).
- legend – Logical value ( ‘TRUE’ – enable, ‘FALSE’ – disable ).
- arrows – Logical value ( ‘TRUE’ – enable, ‘FALSE’ – disable ).
- bounded – Logical value ( ‘TRUE’ – enable, ‘FALSE’ – disable ).
- opacityNoHover – Numeric value of the opacity proportion for node labels text when the mouse is not hovering over them.
- clickAction – A character string with a JavaScript expression to evaluate when a node is clicked.
For instance consider there is a lakh of people living in a city with their friends, and families. The activity of contacting, sharing, and connecting among them can be represented as edges and the people, their friends, and their families are represented as nodes. The scenario of connection among a lack of people can be visualized using a force network.
# Load data
data(MisLinks)
data(MisNodes)
# Plot
forceNetwork(Links = MisLinks, Nodes = MisNodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
Group = "group", opacity = 1)
forceNetwork()
Output:
The ‘MisLinks’ and ‘MisNodes’ are an example of datasets in the ‘networkD3’ package that provides a simulated network of links (edges). MisLinks dataset contains columns such as ‘source’, ‘target’, and ‘value’ that describes the source nodes, target nodes, and the strength of the links. MisNodes dataset contains columns such as ‘name’, ‘group’, and ‘size’ that describes the node names, grouping, and sizes.
networkD3 package in R
Data-driven document Network is an R package for creating network graphs which are used for 3-dimensional visualizations of data as network graphs. In R Programming Language networkD3 plots are created using the networkD3 package.
Table of Content
- Simple Network
- Force Network
- Sankey Network
- Radial Network:
- Dendro network
- Chord Network
To use a package in R programming we have to install the package first. For installing the R package in R studio use the command install.packages(“name”). Follow the following steps to get the packages installed on your system.
install.packages('networkD3')
Contact Us