| plotGraph_gg | R Documentation |
Creates a ggplot2-based visualization of DAG structures from exametrika Bayesian network models. Supports BNM, LDLRA, LDB, and BINET models. Design based on TDE figures with items as rounded rectangles and fields as diamonds.
plotGraph_gg(
data,
layout = "sugiyama",
direction = "TB",
node_size = 12,
label_size = 4,
arrow_size = 3,
title = TRUE,
colors = NULL,
fill_by = c("crr", "type"),
fill_limits = NULL,
show_isolated = FALSE,
show_legend = NULL,
legend_position = "right"
)
data |
An object of class "exametrika" with model type BNM, LDLRA, LDB, or BINET. |
layout |
Character string specifying the layout algorithm. Options include "sugiyama" (default, hierarchical), "fr" (Fruchterman-Reingold), "kk" (Kamada-Kawai), "tree", "stress". |
direction |
Character string for hierarchical layout direction.
Controls the direction of arrows and node placement in hierarchical layouts.
Only applies when
For other layouts (e.g., "fr", "kk"), this parameter is ignored. |
node_size |
Numeric value for node size. Default is 12. |
label_size |
Numeric value for label text size inside nodes. Default is 4. |
arrow_size |
Numeric value for arrow size. Default is 3. |
title |
Logical or character. If |
colors |
Character vector. Colors for node types.
For BNM with |
fill_by |
Character. BNM only: how Item nodes are filled.
|
fill_limits |
Numeric vector of length 2, or |
show_isolated |
Logical. Whether to draw nodes with no edges
(items or fields unrelated to all others) for BNM, LDLRA and LDB.
|
show_legend |
Logical. If |
legend_position |
Character. Position of the legend.
One of |
Design follows TDE figure specifications:
BNM: Items shown as circles with numbers inside, shaded by
correct response rate (or a single purple with fill_by = "type")
LDLRA: Items as circles per rank/class, one plot per rank
LDB: Fields shown as green diamonds, one plot per rank
BINET: Integrated graph with Class nodes (blue squares) and Field nodes (green diamonds) as intermediates. Field nodes are smaller and placed between the Class nodes they connect
Direction Guidelines:
Choose the direction that best represents your data structure:
Use TB (default) for traditional hierarchies or causal flows
Use BT for learning progression, skill development, or upward growth
Use LR/RL for temporal sequences or wide-format displays
Auto-Scaling:
The function automatically scales node and arrow sizes based on graph complexity:
1-5 nodes: 100\
6-10 nodes: 80\
11-20 nodes: 60\
21+ nodes: 50\
Arrows maintain a minimum size of 2mm to ensure visibility.
A list of ggplot objects. For BNM, a single-element list. For LDLRA/LDB, one plot per rank/class. For BINET, the integrated graph.
The linetype common option is not applicable to DAG visualization,
as edges are drawn as directed arrows rather than standard lines.
library(exametrika)
library(ggExametrika)
# BNM example
DAG <- matrix(c(
"Item01", "Item02", "Item02", "Item03",
"Item02", "Item04", "Item03", "Item05",
"Item04", "Item05"
), ncol = 2, byrow = TRUE)
items <- J5S10$ItemLabel
adj <- matrix(0, length(items), length(items), dimnames = list(items, items))
adj[DAG] <- 1
result <- BNM(J5S10, adj_matrix = adj)
# Default: Top-to-Bottom (parents on top, arrows point downward)
plots <- plotGraph_gg(result)
plots[[1]]
# Alternative directions
plotGraph_gg(result, direction = "BT")[[1]] # Bottom-to-Top
plotGraph_gg(result, direction = "LR")[[1]] # Left-to-Right
plotGraph_gg(result, direction = "RL")[[1]] # Right-to-Left
# Force-directed layout (no direction parameter)
plotGraph_gg(result, layout = "fr")[[1]]
# Fixed 0-1 color scale (comparable across plots) or a single color
plotGraph_gg(result, fill_limits = c(0, 1))[[1]]
plotGraph_gg(result, fill_by = "type")[[1]]
# Custom title
plotGraph_gg(result, title = "My Network Model")[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.