Simple Network
A simple network is a basic form of a Forced-directed network, we can use Force network to create a Simple network by providing appropriate data and customization options. For a simple form of a Force-directed network, we can use a simple network (). It works based on a “node-link” diagram and is connected by edges. It provides us with amazing animation with an intuitive way of observing data and also allows us to tweak the networks with cursors.
Syntax:
simpleNetwork(Data, Source = 1, Target = 2, height = NULL, width = NULL, linkDistance = 50
,charge = -30, fontSize = 7, fontFamily = “serif”, linkColour = “#666”,
nodeColour = “#3182bd”,opacity = 0.6, zoom = F)
Arguments:
- Data – A data frame with three columns. The first two are the names of the linked node. The third column is an edge value.
- Source – If
Source = NULL
then the first column of the data frame is treated as the source. Network source variable in the data frame. - Target – If
Target = NULL
, then the data frame’s second column is treated as the target. Network target variable in the data frame. - height – Height for the network graph’s frame area in pixels.
- width – Width for the network graph’s frame area in pixels.
- link distance – The Numeric distance between the links in pixels.
- charge – The Numeric value indicates either the node repulsion’s strength (negative value) or attraction (positive value).
- font Size – The Numeric font size in pixels for the node text labels.
- font Family – Font family for the node text labels.
- linkColour – A Character string defining the color you want the link lines to be.
- nodeColour – A Character string defining the color you want the node circles 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 ).
For Instance, we have a group of five friends named Sam, Sai, Robert, Tom, and Murphy. They are talking and sharing some information among themselves this simple conversation among those friends is represented as edges and the five friends are represented as nodes. This scenario of discussion among them can be visualized in a simple network.
# Load package
library(networkD3)
# Create data
X <- c("A","A","A","A",
"B","C","B","D","C")
Y <- c("C","B","D","E",
"K","J","G","H","I")
networkData <- data.frame(X,Y)
# Plot
simpleNetwork(networkData, fontFamily='fantasy', nodeColour = 'green')
Output:
Install the package and load the package “networkD3” using the library(networkD3).
- Create a variable X and store a set of data as a vector.
- Create another variable Y and store a set of other data as a vector.
- Create a dataframe using data. frame(X, Y) to store X and Y values and store them in the networkData variable.
- Use simple network () to plot the data as a network graph, network data is the input data, ‘fantasy’ is the font family, and ‘green’ is the node color.
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')