Learn R Programming

stCEG (version 0.1.0)

update_node_colours: Update Node Colours in an Event Tree

Description

This function updates the colours of nodes in an event tree based on user-defined groups while ensuring that nodes with the same colour have consistent outgoing edge labels.

Usage

update_node_colours(
  event_tree_obj,
  node_groups,
  colours,
  level_separation = 1000,
  node_distance = 300
)

Value

A list containing:

  • $stagedtree: A visNetwork object representing the updated event tree with coloured nodes.

  • $filtereddf: The filtered data frame, returned invisibly.

Arguments

event_tree_obj

A list containing the event tree object (possibly with node deletion). It should include:

  • $eventtree$x$nodes: A data frame of nodes.

  • $eventtree$x$edges: A data frame of edges.

  • $filtereddf: A filtered data frame associated with the event tree.

node_groups

A list of character vectors, where each vector contains node IDs belonging to a specific group.

colours

A character vector of colour codes corresponding to each node group. The length of colours must match node_groups.

level_separation

Numeric value specifying the spacing between levels in the hierarchical layout. Default is 1000.

node_distance

Numeric value specifying the distance between nodes in the layout. Default is 300.

Details

The function follows these steps:

  • Assigns colours to nodes based on the specified node_groups.

  • Ensures that no node appears in multiple groups (raises an error if duplicates exist).

  • Checks that all nodes with the same colour have identical outgoing edge labels.

  • Updates the event tree visualization using visNetwork.

Examples

Run this code
data <- homicides
event_tree <- create_event_tree(data, columns = c(1,2,4,5), "both")
event_tree

# Define node groups and colours
node_groups <- list(c("s1", "s2"), c("s3", "s4"))
colours <- c("#BBA0CA", "#8AC6D0")

# Apply colours to the event tree
coloured_tree <- update_node_colours(event_tree, node_groups, colours)
coloured_tree

Run the code above in your browser using DataLab