update_node_colours {stCEG} | R Documentation |
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
)
Arguments
event_tree_obj |
A list containing the event tree object (possibly with node deletion). It should include:
|
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 |
level_separation |
Numeric value specifying the spacing between levels in the hierarchical layout.
Default is |
node_distance |
Numeric value specifying the distance between nodes in the layout.
Default is |
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
.
Value
A list containing:
-
$stagedtree
: AvisNetwork
object representing the updated event tree with coloured nodes. -
$filtereddf
: The filtered data frame, returned invisibly.
Examples
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