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 |
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.
example_incidmat
example_incidmat
A data frame with 798 rows and 8 binary variables:
A dataset consisting of anonymized patients (n=798) and symptoms (d=8), where each patient has one or more symptoms.
example_nodelist
example_nodelist
A data frame with 806 rows and 5 columns:
Node ID of patients and symptoms.
Cluster membership found by BipartiteModularityMaximization. Can be changed to any customized cluster membership.
X coordinates found by Fruchterman & Reingold layout. Can be changed to any customized coordinates.
Y coordinates found by Fruchterman & Reingold layout. Can be changed to any customized coordinates.
Indicating whether a node is a patient (assigned 1) or a symptom (assigned 2).
Takes the nodelist of a network and return an updated nodelist with the exploded coordinates.
explode_coordinates(nodelist, radius = 1)
explode_coordinates(nodelist, radius = 1)
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. |
A nodelist with new node layout coordinates generated from the algorithm. This is a new dataframe with 4 colums: Label, newX, newY, Cluster.
exploded_coords=explode_coordinates(example_nodelist,radius=1.2)
exploded_coords=explode_coordinates(example_nodelist,radius=1.2)
Generate edgelist from incidence matrix of a bipartite network
get_edgelist_from_incidmat(incidence_matrix)
get_edgelist_from_incidmat(incidence_matrix)
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. |
A dataframe with 3 columns: nodesR, nodesC, values.
example_edgelist=get_edgelist_from_incidmat(example_incidmat)
example_edgelist=get_edgelist_from_incidmat(example_incidmat)
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.
get_explode_nodelist(nodelist, radius = 1)
get_explode_nodelist(nodelist, radius = 1)
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. |
A new nodelist with exploded coordinates, which is a dataframe including 5 columns: Label, X, Y, Color, baseShape.
exploded_nodelist=get_explode_nodelist(example_nodelist,radius=1.2)
exploded_nodelist=get_explode_nodelist(example_nodelist,radius=1.2)
Format a nodelist for plotting using the new coordinates found by ExplodeLayout
get_nodelist_for_plotting(nodelist, new_coordinates)
get_nodelist_for_plotting(nodelist, new_coordinates)
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. |
A dataframe including 5 columns: Label, X, Y, Color, baseShape.
exploded_coords=explode_coordinates(example_nodelist,radius=1.2) plotting_nodelist=get_nodelist_for_plotting(example_nodelist,exploded_coords)
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.
plot_binet_ggplot2(nodelist, incidence_matrix, plotlabel = "c")
plot_binet_ggplot2(nodelist, incidence_matrix, plotlabel = "c")
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'. |
a ggplot2 object p which can be shown using print(p).
exploded_nodelist=get_explode_nodelist(example_nodelist,radius=1.2) p=plot_binet_ggplot2(exploded_nodelist,example_incidmat) print(p)
exploded_nodelist=get_explode_nodelist(example_nodelist,radius=1.2) p=plot_binet_ggplot2(exploded_nodelist,example_incidmat) print(p)