data(tpc_example)
# Define a `Knowledge` object with tiers
kn_tiered <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
old ~ starts_with("old")
)
)
# Simple plot (default column orientation)
plot(kn_tiered)
# Plot with row orientation
plot(kn_tiered, orientation = "rows")
# Plot with custom node styling, edge width/arrow size and edge colors
kn <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
old ~ starts_with("old")
),
child_x1 %-->% child_x2, # required edge
youth_x4 %!-->% youth_x3 # forbidden edge
)
plot(
kn,
node_style = list(
fill = "lightblue", # Fill color
col = "darkblue", # Border color
lwd = 2, # Border width
padding = 4, # Text padding (mm)
size = 1.2 # Size multiplier
),
edge_style = list(
lwd = 1.5, # Edge width
arrow_size = 4 # Arrow size (mm)
),
required_col = "darkgreen",
forbidden_col = "darkorange"
)
# To override a specific edge style which is required/forbidden
# you need to target that individual node:
kn <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
old ~ starts_with("old")
),
child_x1 %-->% c(child_x2, youth_x4), # required edges
youth_x4 %!-->% c(youth_x3, oldage_x5) # forbidden edges
)
# Edge from child_x1 to child_x2 will be orange, but edge from child_x1 to youth_x4
# will be required_col (blue) since we only override the child_x1 to child_x2 edge.
# Similarly, edge from youth_x4 to youth_x3 will be yellow, but edge from youth_x4
# to oldage_x5 will be forbidden_col (red).
plot(
kn,
edge_style = list(
by_edge = list(
child_x1 = list(
child_x2 = list(col = "orange", fill = "orange")
),
youth_x4 = list(
youth_x3 = list(col = "yellow", fill = "yellow")
)
)
),
required_col = "blue",
forbidden_col = "red"
)
# Define a `Knowledge` object without tiers
kn_untiered <- knowledge(
tpc_example,
child_x1 %-->% c(child_x2, youth_x3),
youth_x4 %!-->% oldage_x5
)
# Plot with default layout
plot(kn_untiered)
# With a custom defined layout
custom_layout <- data.frame(
name = c("child_x1", "child_x2", "youth_x3", "youth_x4", "oldage_x5", "oldage_x6"),
x = c(0, 1, 2, 2, 3, 4),
y = c(0, 1, 0, -1, 0, 1)
)
plot(kn_untiered, layout = custom_layout)
Run the code above in your browser using DataLab