| plot_structure | R Documentation |
Developer-facing visualizer for the finger-tree backing any immutables
structure (flexseq, ordered_sequence, priority_queue,
interval_index). The S3 plot() methods on those classes forward to
this function, but plot_structure() is also callable directly and gives
access to the full node_label API for custom label formatting. Requires
the igraph package (listed in Suggests).
plot_structure(
t1,
vertex.size = 15,
vertex.shape = "rounded_rect",
edge.width = 1,
label_edges = FALSE,
title = NULL,
node_label = "value",
label.cex = NULL,
asp = NA,
legend = TRUE,
...
)
t1 |
A finger-tree-backed immutables structure. |
vertex.size |
Passed to |
vertex.shape |
Vertex shape. Defaults to |
edge.width |
Edge width passed to |
label_edges |
If |
title |
Optional plot title. |
node_label |
Either one of the preset modes
Measure values are exposed as-is, including list-valued measures
(e.g. the built-in |
label.cex |
Numeric scalar controlling label text size (passed as
|
asp |
Plot aspect ratio (physical y-unit / physical x-unit).
Default |
legend |
If |
... |
Additional arguments passed to |
Invoked for its side effect (draws to the active graphics
device). Returns NULL invisibly.
measure_monoid(), add_monoids()
if (requireNamespace("igraph", quietly = TRUE)) {
t <- as_flexseq(letters[1:8])
plot_structure(t, title = "Finger tree")
# Label every node with its subtree size (leaves contribute 1).
plot_structure(as_flexseq(1:10), node_label = function(node) {
paste0(node$type, "\n.size=", node$measures$.size)
})
# Custom monoid: subtree sum of numeric payloads. Structural nodes show
# the accumulated total; leaves show their own contribution.
sum_monoid <- measure_monoid(`+`, 0, function(el) el)
xs <- add_monoids(as_flexseq(c(3, 1, 4, 1, 5, 9, 2, 6)),
list(sum = sum_monoid))
plot_structure(xs, node_label = function(node) {
if(node$type == "Element") sprintf("%g\nsum=%g", node$element, node$measures$sum)
else sprintf("%s\nsum=%g", node$type, node$measures$sum)
})
# List-valued built-in measure: priority_queue's .pq_min tracks the min
# priority seen in a subtree as list(has, priority). Unpack in the label.
pq <- priority_queue("task-a", "task-b", "task-c",
priorities = c(5, 1, 3))
plot_structure(pq, node_label = function(node) {
m <- node$measures$.pq_min
if(node$type == "Element") {
sprintf("%s\np=%g", node$element$value, node$element$priority)
} else if(isTRUE(m$has)) {
sprintf("%s\nmin=%g", node$type, m$priority)
} else {
node$type
}
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.