layout_networks: Calculate the Coordinates of Nodes

View source: R/layout_networks.R

layout_networksR Documentation

Calculate the Coordinates of Nodes

Description

[Experimental]

The function implements different layout algorithms from ggraph and graphlayouts. It also implements a dynamic process of computation of coordinates for list of tibble graphs, in order for the coordinates to be consistent between graphs.

Usage

layout_networks(
  graphs,
  node_id,
  layout,
  compute_dynamic_coordinates = FALSE,
  save_coordinates = FALSE,
  ...
)

Arguments

graphs

A tibble graph from tidygraph, a list of tibble graphs or a data frame.

node_id

The column with the unique identifier of each node.

layout

The type of layout to create. All strings accepted by the algorithm argument can also be supplied directly into layout. See ggraph::ggraph() for more details on layouts.

compute_dynamic_coordinates

When you have a list of tibble graphs and that some nodes are in multiple graphs, you may want that each node in several graphs has relatively similar coordinates. Set compute_dynamic_coordinates to TRUE to take into account the coordinates of the nodes in the n-1 tibble graph, during the computation of the coordinates of the n tibble graph.

save_coordinates

If you are running the function on the same object, the already existing columns x and y will be erased and new values will be computed. Set save_coordinates to TRUE to save the x and y values in columns with a name depending of the layout method used.

...

Additional arguments of the layout compatible with the function. See ggraph::graph(), ggraph::layout_tbl_graph_igraph() and graphlayouts::graphslayouts() for more information.

Details

The function allows for the use of different layouts implemented in ggraph and graphlayouts. However, some layout of graphlayouts are not working with this function. Also, layouts do not all take as input pre-determined coordinates, meaning that the compute_dynamic_coordinates argument does not work with all layout. Please check if the layout used allows a parameter called coord.

Value

The same tibble graph or list of tibble graphs with a column x and y, and also additional column x_{layout} and y_{layout} if you have set save_coordinates to TRUE.

Examples

library(networkflow)

nodes <- Nodes_stagflation |>
dplyr::rename(ID_Art = ItemID_Ref) |>
dplyr::filter(Type == "Stagflation")

references <- Ref_stagflation |>
dplyr::rename(ID_Art = Citing_ItemID_Ref)

temporal_networks <- build_dynamic_networks(nodes = nodes,
directed_edges = references,
source_id = "ID_Art",
target_id = "ItemID_Ref",
time_variable = "Year",
cooccurrence_method = "coupling_similarity",
time_window = 20,
edges_threshold = 1,
overlapping_window = TRUE,
filter_components = TRUE)

temporal_networks <- layout_networks(temporal_networks,
node_id = "ID_Art",
layout = "fr",
compute_dynamic_coordinates = TRUE)

temporal_networks [[1]]


agoutsmedt/networkflow documentation built on March 15, 2023, 11:51 p.m.