| make_tikz | R Documentation |
Generates LaTeX TikZ code from a Disco, Knowledge, or
caugi::caugi object, preserving node positions, labels, and visual styles.
Edges are rendered with arrows, line widths, and colors.
The output is readable LaTeX code that can be
directly compiled or modified.
make_tikz(
x,
...,
scale = 10,
full_doc = TRUE,
bend_edges = FALSE,
bend_angle = 25,
tier_label_pos = c("above", "below", "left", "right")
)
x |
A |
... |
Additional arguments passed to |
scale |
Numeric scalar. Scaling factor for node coordinates. Default is |
full_doc |
Logical. If |
bend_edges |
Logical. If |
bend_angle |
Numeric scalar. Angle in degrees for bending arrows when
|
tier_label_pos |
Character string specifying the position of tier labels
relative to the tier rectangles. Must be one of |
The function calls plot() to generate a caugi::caugi_plot object, then
traverses the plot object's grob structure to extract nodes and
edges. Supported features include:
Nodes
Fill color and draw color (supports both named colors and custom RGB values)
Font size
Coordinates are scaled by the scale parameter
Edges
Line color and width
Arrow scale
Optional bending to reduce overlapping arrows
The generated TikZ code uses global style settings, and edges are connected to nodes by name (as opposed to hard-coded coordinates), making it easy to modify the output further if needed.
A character string containing LaTeX TikZ code. Depending on
full_doc, this is either:
a complete LaTeX document (full_doc = TRUE), or
only the tikzpicture environment (full_doc = FALSE).
################# Convert Knowledge to Tikz ################
data(num_data)
kn <- knowledge(
num_data,
X1 %-->% X2,
X2 %!-->% c(X3, Y),
Y %!-->% Z
)
# Full standalone document
tikz_kn <- make_tikz(kn, scale = 10, full_doc = TRUE)
cat(tikz_kn)
# Only the tikzpicture environment
tikz_kn_snippet <- make_tikz(kn, full_doc = FALSE)
cat(tikz_kn_snippet)
# With bent edges
tikz_bent <- make_tikz(
kn,
full_doc = FALSE,
bend_edges = TRUE
)
cat(tikz_bent)
# With a color not supported by default TikZ colors; will fall back to RGB
tikz_darkblue <- make_tikz(
kn,
node_style = list(fill = "darkblue"),
full_doc = FALSE
)
cat(tikz_darkblue)
# With tiered knowledge
data(tpc_example)
kn_tiered <- knowledge(
tpc_example,
tier(
child ~ starts_with("child"),
youth ~ starts_with("youth"),
old ~ starts_with("old")
)
)
tikz_tiered_kn <- make_tikz(
kn_tiered,
full_doc = FALSE
)
cat(tikz_tiered_kn)
################# Convert disco to Tikz ################
data(num_data)
kn <- knowledge(
num_data,
X1 %-->% X2,
X2 %!-->% c(X3, Y),
Y %!-->% Z
)
pc_bnlearn <- pc(engine = "bnlearn", test = "fisher_z", alpha = 0.05)
disco_kn <- disco(data = num_data, method = pc_bnlearn, knowledge = kn)
tikz_snippet <- make_tikz(disco_kn, scale = 10, full_doc = FALSE)
cat(tikz_snippet)
################# Convert caugi objects to Tikz ################
cg <- caugi::caugi(A %-->% B + C)
tikz_snippet <- make_tikz(
cg,
node_style = list(fill = "red"),
scale = 10,
full_doc = FALSE
)
cat(tikz_snippet)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.