Skip to contents

Converts the output from analyze_employment_transitions() to the node-edge format required by g6r for interactive network visualization.

Usage

convert_transitions_to_g6r(
  transitions_data,
  node_size_metric = "total_degree",
  edge_width_metric = "weight",
  min_weight_threshold = 1,
  node_color_palette = NULL,
  edge_color = "#666666",
  include_self_loops = FALSE,
  consolidation_info = TRUE
)

Arguments

transitions_data

Output from analyze_employment_transitions() (data.table format) or transition matrix (matrix format). May include consolidated transition data if analyzed with consolidation_mode = "temporal".

node_size_metric

Character string specifying which metric to use for node sizing. Options: "in_degree" (incoming transitions), "out_degree" (outgoing transitions), "total_degree" (sum of both), "weight" (total transition weight). Default: "total_degree"

edge_width_metric

Character string specifying which metric to use for edge width. Options: "weight" (transition count), "transition_duration" (avg unemployment duration), or any statistics variable name. Default: "weight"

min_weight_threshold

Numeric. Minimum transition weight to include in visualization. Helps focus on significant transitions by filtering out rare events. Default: 1

node_color_palette

Character vector of colors for nodes. Should be colorblind-friendly. Default: uses viridis::viridis() palette

edge_color

Character string for edge color. When transitions are consolidated, can be set to indicate consolidation status. Default: "#666666" (gray)

include_self_loops

Logical. Whether to include self-loops (transitions from state to same state). Default: FALSE

consolidation_info

Logical. Whether to include consolidation information in node/edge tooltips and styling. Only applicable when transitions_data contains consolidated periods. Default: TRUE

Value

List with two elements:

  • nodes: Data frame with columns: id, label, value (for sizing), color, total_transitions, in_degree, out_degree

  • edges: Data frame with columns: source, target, weight, width (for styling), color, transition_duration, and any additional statistics from original data

Examples

if (FALSE) { # \dontrun{
library(data.table)
library(g6R)

# Create sample employment data
employment_data <- data.table(
  id = 1:6,
  cf = c("PERSON001", "PERSON001", "PERSON001", "PERSON002", "PERSON002", "PERSON002"),
  INIZIO = as.Date(c("2023-01-01", "2023-04-01", "2023-08-01", 
                     "2023-02-01", "2023-06-01", "2023-10-01")),
  FINE = as.Date(c("2023-02-28", "2023-05-31", "2023-12-31", 
                   "2023-04-30", "2023-08-31", "2023-12-31")),
  prior = c(1, 0, 1, 1, 1, 0),
  company = c("CompanyA", "CompanyB", "CompanyC", "CompanyD", "CompanyE", "CompanyF"),
  salary = c(50000, 25000, 60000, 55000, 65000, 30000)
)

# Process through pipeline
result <- process_employment_pipeline(
  original_data = employment_data,
  merge_columns = c("company", "salary")
)

# Analyze transitions
transitions <- analyze_employment_transitions(
  pipeline_result = result,
  transition_variable = "company",
  statistics_variables = c("salary")
)

# Convert to g6r format
g6_data <- convert_transitions_to_g6r(transitions)

# Alternative: convert transition matrix
matrix_transitions <- analyze_employment_transitions(
  pipeline_result = result,
  transition_variable = "company",
  output_transition_matrix = TRUE
)
g6_matrix_data <- convert_transitions_to_g6r(matrix_transitions)
} # }