Package 'ExplodeLayout'

Title: Calculate Exploded Coordinates Based on Original Node Coordinates and Node Clustering Membership
Description: Current layout algorithms such as Kamada Kawai do not take into consideration disjoint clusters in a network, often resulting in a high overlap among the clusters, resulting in a visual “hairball” that often is uninterpretable. The ExplodeLayout algorithm takes as input (1) an edge list of a unipartite or bipartite network, (2) node layout coordinates (x, y) generated by a layout algorithm such as Kamada Kawai, (3) node cluster membership generated from a clustering algorithm such as modularity maximization, and (4) a radius to enable the node clusters to be “exploded” to reduce their overlap. The algorithm uses these inputs to generate new layout coordinates of the nodes which “explodes” the clusters apart, such that the edge lengths within the clusters are preserved, while the edge lengths between clusters are recalculated. The modified network layout with nodes and edges are displayed in two dimensions. The user can experiment with different explode radii to generate a layout which has sufficient separation of clusters, while reducing the overall layout size of the network. This package is a basic version of an earlier version called [epl]<https://github.com/UTMB-DIVA-Lab/epl> that searched for an optimal explode radius, and offered multiple ways to separate clusters in a network (Bhavnani et al(2017) <PMID: 28815099>). The example dataset is for a bipartite network, but the algorithm can work also for unipartite networks.
Authors: Suresh K. Bhavnani [aut], Weibin Zhang [cre, aut]
Maintainer: Weibin Zhang <[email protected]>
License: MIT + file LICENSE
Version: 0.1.2
Built: 2025-02-28 04:16:28 UTC
Source: https://github.com/cran/ExplodeLayout

Help Index


Sample dataset of a bipartite network..

Description

The sample dataset consists of a simulated data consisting of patients (n=798) and symptoms (d=8), where each patient has one or more symptoms referred to here as an incidence matrix.

Usage

example_incidmat

Format

A data frame with 798 rows and 8 binary variables:

Symptom_1
Symptom_2
Symptom_3
Symptom_4
Symptom_5
Symptom_6
Symptom_7
Symptom_8

Example nodelist file of a bipartite network.

Description

A dataset consisting of anonymized patients (n=798) and symptoms (d=8), where each patient has one or more symptoms.

Usage

example_nodelist

Format

A data frame with 806 rows and 5 columns:

Label

Node ID of patients and symptoms.

Cluster

Cluster membership found by BipartiteModularityMaximization. Can be changed to any customized cluster membership.

X

X coordinates found by Fruchterman & Reingold layout. Can be changed to any customized coordinates.

Y

Y coordinates found by Fruchterman & Reingold layout. Can be changed to any customized coordinates.

Entity

Indicating whether a node is a patient (assigned 1) or a symptom (assigned 2).


Explode the old coordinates using cluster membership

Description

Takes the nodelist of a network and return an updated nodelist with the exploded coordinates.

Usage

explode_coordinates(nodelist, radius = 1)

Arguments

nodelist

A nodelist is a dataframe including at least 4 columns: Label, X, Y, Cluster. Label is the node ID. They must be unique character strings. X and Y are the original coordinates. Cluster is the node clustering membership. They must be integers ranging from 1 to the number of clusters.

radius

The radius of the used to explode the clusters, which defaults to 1.

Value

A nodelist with new node layout coordinates generated from the algorithm. This is a new dataframe with 4 colums: Label, newX, newY, Cluster.

Examples

exploded_coords=explode_coordinates(example_nodelist,radius=1.2)

Generate edgelist from incidence matrix of a bipartite network

Description

Generate edgelist from incidence matrix of a bipartite network

Usage

get_edgelist_from_incidmat(incidence_matrix)

Arguments

incidence_matrix

A matrix where row names and column names are the node ID of a bipartite network. An element of the i-th row and j-th column of the matrix is 0 if node on row i is not connected to node on column j, and edge weight if they are connected.

Value

A dataframe with 3 columns: nodesR, nodesC, values.

Examples

example_edgelist=get_edgelist_from_incidmat(example_incidmat)

Explode the old coordinates using cluster membership and generate nodelist for plotting

Description

Takes the nodelist of a network and return an updated nodelist with the exploded coordinates based on radius, node color based on cluster, and node shape based on entity.

Usage

get_explode_nodelist(nodelist, radius = 1)

Arguments

nodelist

A nodelist is a dataframe including at least 5 columns: Label, X, Y, Cluster, Entity. Label is the node ID. They must be unique character strings. X and Y are the original coordinates. Cluster is the node clustering membership. They must be integers ranging from 1 to the number of clusters. Entity indicates which part of the bipartite network a node belongs to. (Can be either 1 or 2.)

radius

The explode radius of the projecting circle. Default to 1.

Value

A new nodelist with exploded coordinates, which is a dataframe including 5 columns: Label, X, Y, Color, baseShape.

Examples

exploded_nodelist=get_explode_nodelist(example_nodelist,radius=1.2)

Format a nodelist for plotting using the new coordinates found by ExplodeLayout

Description

Format a nodelist for plotting using the new coordinates found by ExplodeLayout

Usage

get_nodelist_for_plotting(nodelist, new_coordinates)

Arguments

nodelist

A dataframe including at least 3 columns: Label, Cluster, Entity. Entity is either 1 or 2, indicating which part of the bipartite network a node is in.

new_coordinates

A dataframe including at least 3 columns: Label, newX, newY.

Value

A dataframe including 5 columns: Label, X, Y, Color, baseShape.

Examples

exploded_coords=explode_coordinates(example_nodelist,radius=1.2)
plotting_nodelist=get_nodelist_for_plotting(example_nodelist,exploded_coords)

Plot bipartite network given node list (label, coordinates, shape, color) and incidence matrix.

Description

Plot bipartite network given node list (label, coordinates, shape, color) and incidence matrix.

Usage

plot_binet_ggplot2(nodelist, incidence_matrix, plotlabel = "c")

Arguments

nodelist

A dataframe of at least 5 columns: Label, X, Y, Color, baseShape.

incidence_matrix

A matrix where row names and column names are the node ID of a bipartite network. An element of the i-th row and j-th column of the matrix is 0 if node on row i is not connected to node on column j, and edge weight if they are connected.

plotlabel

A string indicating whether to add node label text. 'r' for rows, 'c' for columns, and 'rc' for both rows and columns of the incidence_matrix. All other strings will be ignored. Default to 'c'.

Value

a ggplot2 object p which can be shown using print(p).

Examples

exploded_nodelist=get_explode_nodelist(example_nodelist,radius=1.2)
p=plot_binet_ggplot2(exploded_nodelist,example_incidmat)
print(p)