networks_to_alluv: Create a data.frame suitable for alluvial graph projection

View source: R/networks_to_alluv.R

networks_to_alluvR Documentation

Create a data.frame suitable for alluvial graph projection

Description

This function creates a data.frame that can be easily plotted with ggalluvial from a list of networks.

Usage

networks_to_alluv(
  list_graph = NA,
  intertemporal_cluster_column = "intertemporal_name",
  node_id = NA,
  summary_cl_stats = TRUE,
  keep_color = TRUE,
  color_column = "color",
  keep_cluster_label = TRUE,
  cluster_label_column = "cluster_label"
)

Arguments

list_graph

Your list with all networks

intertemporal_cluster_column

The column with the identifier of the inter-temporal cluster. If you have used add_clusters() and merge_dynamic_clusters(), it is of the form dynamic_cluster_{clustering_method}.

node_id

The column with the unique identifier of each node.

summary_cl_stats

If set to TRUE, the data.frame will contain a list of variable that summarize cluster statistics of the alluvial. These variables can be particularly useful to filter smaller communities when plotting according to different variables:

  • share_cluster_alluv is the percentage share of a given cluster across all time windows;

  • share_cluster_window is the percentage share of a given cluster in a given time window;

  • share_cluster_max is the highest value of share_cluster_window for a given cluster across all individual time windows;

  • length_cluster is the number of time windows a cluster exists.

keep_color

Set to TRUE (by default) if you want to keep the column with the color associated to the different categories of intertemporal_cluster_column. Such a column exists in your list of tibble graphs if you have use color_networks().

color_column

The name of the column with the colors of the categories in intertemporal_cluster_column. By default, "color", as it is the column name resulting from the use of color_networks().

keep_cluster_label

Set to TRUE if you want to keep the column with a name/label associated to the different categories of intertemporal_cluster_column. Such a column exists in your list of tibble graphs if you have use name_clusters().

cluster_label_column

The name of the column with the name/label associated to the categories in intertemporal_cluster_column. By default, "cluster_label", as it is the column name resulting from the use of name_clusters().

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,
verbose = FALSE)

temporal_networks <- add_clusters(temporal_networks,
objective_function = "modularity",
clustering_method = "leiden",
verbose = FALSE)

temporal_networks <- merge_dynamic_clusters(temporal_networks,
cluster_id = "cluster_leiden",
node_id = "ID_Art",
threshold_similarity = 0.51,
similarity_type = "partial")

temporal_networks <- name_clusters(graphs = temporal_networks,
method = "tf-idf",
name_merged_clusters = TRUE,
cluster_id = "dynamic_cluster_leiden",
text_columns = "Title",
nb_terms_label = 5,
clean_word_method = "lemmatise")

temporal_networks <- color_networks(graphs = temporal_networks,
column_to_color = "dynamic_cluster_leiden",
color = NULL)

alluv_dt <- networks_to_alluv(temporal_networks,
intertemporal_cluster_column = "dynamic_cluster_leiden",
node_id = "ID_Art")

alluv_dt[1:5]


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