View source: R/plot_state_frequencies.R
| plot_state_frequencies | R Documentation |
Visualise state (node) frequency distributions across groups for any
Nestimate object that carries sequence data: a single netobject,
a netobject_group, an mcml model, or an htna network.
plot_state_frequencies(x, ...)
## S3 method for class 'netobject'
plot_state_frequencies(
x,
style = "marimekko",
metric = "prop",
label = "prop",
legend = "auto",
legend_dir = "auto",
legend_frame = "none",
sort_states = "frequency",
colors = NULL,
label_size = 3.5,
abbreviate = FALSE,
include_macro = FALSE,
combine = "auto",
ncol = NULL,
node_groups = NULL,
...
)
## S3 method for class 'htna'
plot_state_frequencies(
x,
style = "marimekko",
metric = "prop",
label = "prop",
legend = "auto",
legend_dir = "auto",
legend_frame = "none",
sort_states = "frequency",
colors = NULL,
label_size = 3.5,
abbreviate = FALSE,
include_macro = FALSE,
combine = "auto",
ncol = NULL,
node_groups = NULL,
...
)
## S3 method for class 'mcml'
plot_state_frequencies(
x,
style = "marimekko",
metric = "prop",
label = "prop",
legend = "auto",
legend_dir = "auto",
legend_frame = "none",
sort_states = "frequency",
colors = NULL,
label_size = 3.5,
abbreviate = FALSE,
include_macro = FALSE,
combine = "auto",
ncol = NULL,
node_groups = NULL,
...
)
## S3 method for class 'netobject_group'
plot_state_frequencies(
x,
style = "marimekko",
metric = "prop",
label = "prop",
legend = "auto",
legend_dir = "auto",
legend_frame = "none",
sort_states = "frequency",
colors = NULL,
label_size = 3.5,
abbreviate = FALSE,
include_macro = FALSE,
combine = "auto",
ncol = NULL,
node_groups = NULL,
...
)
## Default S3 method:
plot_state_frequencies(x, ...)
x |
A |
... |
Reserved for future use. |
style |
One of:
For chi-square mosaics of a (group x state) contingency table, use
|
metric |
For |
label |
Inline tile / bar annotation. All formats render on a single line.
|
legend |
Legend position. |
legend_dir |
Legend internal layout: |
legend_frame |
|
sort_states |
One of |
colors |
Optional character vector overriding the default Okabe-Ito state palette. Length must be at least the number of unique states. |
label_size |
Numeric size of inline labels (max size when ggfittext is installed – text auto-shrinks per tile). |
abbreviate |
Abbreviate state names. |
include_macro |
For |
combine |
For |
ncol |
For |
node_groups |
Optional named character vector mapping node labels to semantic groups. When supplied, panels (or bars) are coloured / annotated by group rather than by individual state, so state-level palettes can collapse onto a smaller categorical legend. |
The marimekko layout is dispatched per class:
For mcml, where states partition cleanly into clusters,
the chart is a hierarchical 2D marimekko: cluster columns of width
proportional to cluster total, segments stacked vertically with
heights proportional to within-cluster state proportions.
For all other classes (netobject, netobject_group,
htna), each group is rendered as its own panel containing a
squarified treemap: each state becomes a rectangular tile whose
AREA is exactly proportional to the state's share within that group.
Single-panel when no groups exist; faceted when groups are present.
The bar style produces horizontal bars (state on the y-axis), faceted by group when groups exist. All variants use the Okabe-Ito palette.
A state_freq object: a list with the rendered $plot
(a ggplot or gtable), the tidy $table (a
data.frame with columns group, state, count,
proportion), and the call's $style, $metric,
$source_class. The class supports print() (shows the
tidy table in the console), plot() (renders the chart), and
as.data.frame() (returns the table).
if (requireNamespace("ggplot2", quietly = TRUE)) {
data(group_regulation_long, package = "Nestimate")
nw <- build_network(group_regulation_long,
method = "relative", format = "long",
actor = "Actor", action = "Action",
order = "Time", group = "Course")
res <- plot_state_frequencies(nw)
print(res) # tidy frequency table in the console
plot(res) # ggplot chart
head(as.data.frame(res))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.