| plot_grapht | R Documentation |
This function provides users with an easy way to graph dynamic network data for exploration and presentation.
It builds upon this package's graphr() function,
and inherits all the same features and arguments.
See graphr() for more.
However, it uses the {gganimate} package to animate the changes
between successive iterations of a network.
This is useful for networks in which the ties and/or the node or tie
attributes are changing, including networks whose node composition
changes over time: every node that ever appears is assigned a stable
position, and nodes fade in and out in place as they enter and exit
the network.
By default node positions transition smoothly between waves using
the dynamic stress layout from {graphlayouts}
(graphlayouts::layout_as_dynamic()), which anchors each wave's
layout to a reference layout of the aggregate network.
The alpha argument controls this trade-off:
0 lets each wave's layout follow that wave's structure freely,
while 1 freezes every node at its aggregate position.
When another layout is requested,
a single static layout is computed on the aggregate
(union of waves) network instead, so that positions remain constant.
Unlike graphr(), grapht() uses this dynamic stress layout by default
even for two-mode networks (rather than a layered layout, which would
collapse many nodes onto a line); the two modes remain distinguishable
by node shape.
For networks with more than 30 nodes, node labels are suppressed by
default to keep frames legible; pass labels = TRUE to force them.
grapht() returns a {ggplot2}-compatible object that can be
extended with additional layers such as ggplot2::labs(),
ggplot2::theme(), scale functions, and others,
just like plots produced by graphr() and graphs().
The animation is rendered when the object is printed or displayed.
Users who want more control over animation parameters can call
gganimate::animate() directly on the returned object.
The visual appearance is consistent with graphr():
nodes use fillable shapes with the fill aesthetic,
the same colour palettes are applied,
directed networks receive arrowheads (see edge_arrows),
signed networks distinguish positive from negative ties by linetype,
and labels use the current theme font.
Legends transition along with the mapped aesthetics.
A progress bar is shown if it takes some time to encode all the .png files into a .gif.
grapht(
tlist,
layout = NULL,
labels = TRUE,
node_color,
node_shape,
node_size,
edge_color,
edge_size,
isolates = c("keep", "fade"),
alpha = 0.5,
label_repel = TRUE,
edge_arrows = NULL,
keep_isolates = NULL,
...,
node_colour,
edge_colour,
label_dist
)
## S3 method for class 'grapht'
print(x, ...)
tlist |
A manynet-compatible network listed according to
a time attribute, waves, or slices.
This can also be a single manynet network object that encodes time,
which is split automatically by |
layout |
An igraph, ggraph, or manynet layout algorithm.
If not declared, defaults to "configuration" for networks of up to
six nodes, "levels" for connected multilevel networks,
"layered" for other two mode networks,
and "stress" for all other networks.
The "stress" layout of a network of more than 1000 nodes is run at a
looser tolerance ( |
labels |
Which nodes to label, if the network is labelled.
|
node_color, node_colour |
Node variable to be used for coloring the nodes. It is easiest if this is added as a node attribute to the graph before plotting. A categorical variable gives one colour to each category. A measure, such as a centrality or coreness score, is drawn instead as a gradient from the theme's base colour to its highlight colour, with a colourbar in place of the legend. Nodes can also be colored by declaring a color instead. |
node_shape |
Node variable to be used for shaping the nodes. It is easiest if this is added as a node attribute to the graph before plotting. Nodes can also be shaped by declaring a shape instead. |
node_size |
Node variable to be used for sizing the nodes. This can be any continuous variable on the nodes of the network. Since this function expects this to be an existing variable, it is recommended to calculate all node-related statistics prior to using this function. Nodes can also be sized by declaring a numeric size or vector instead. |
edge_color, edge_colour |
Tie variable to be used for coloring the nodes. It is easiest if this is added as an edge or tie attribute to the graph before plotting. Edges can also be colored by declaring a color instead. |
edge_size |
Tie variable to be used for sizing the edges. This can be any continuous variable on the nodes of the network. Since this function expects this to be an existing variable, it is recommended to calculate all edge-related statistics prior to using this function. Edges can also be sized by declaring a numeric size or vector instead. |
isolates |
One of |
alpha |
A number between 0 and 1 controlling the stability of
node positions across waves when the default dynamic (stress) layout
is used. 0 computes each wave's layout freely,
1 fixes all nodes at their aggregate-network positions.
By default 0.5. Passed to |
label_repel |
Where to put the labels.
The layered layouts ("layered", "lineage", "railway" and "ladder") place each node in a layer, which is where the reader looks for it, so a repelled label there would say less about which node it labels than a fixed offset does. They offset the labels instead, unless a direction is given. |
edge_arrows |
Whether, and at what size, to draw arrowheads on the ties
of a directed network.
By default ( |
keep_isolates |
Deprecated. Use |
... |
Extra arguments to pass on to the layout algorithm, if necessary. |
label_dist |
Deprecated. Give the gap to |
x |
A grapht object to print. |
Unlike graphr(), grapht() does not use ggrepel-based label
repelling (there is no straightforward way to repel labels consistently
across animation frames), so label_repel here instead gives a fixed
offset nudging labels away from their nodes: above them for TRUE,
none for FALSE, and in the direction named for a direction.
A gap in points scales the size of that nudge rather than being used as
repel padding.
labels can select which nodes to label here too, and the selection is
resolved once over all the waves so that the same nodes stay labelled from
frame to frame. Unlike graphr(), though, animations of more than 30 nodes
default to no labels at all rather than to a selection of them.
Some further graphr() features are not available in animations:
node_group hulls, edge bundling, curved arcs for reciprocated ties,
and self-loops (loops are not drawn; a note is printed if present).
Note too that, where no layout is named, grapht() defaults to
the "stress" layout for every network rather than choosing one by
the network's shape as graphr() does,
so that nodes move smoothly from one wave to the next.
A layout named explicitly is still used, computed on the aggregate network.
A {ggplot2}-compatible object with {gganimate} animation layers.
This object can be extended with additional {ggplot2} layers
(e.g. + labs(subtitle = "My subtitle")).
When printed or displayed, the animation is rendered as a .gif.
For more control over animation parameters,
pass the result to gganimate::animate() directly.
https://blog.schochastics.net/posts/2021-09-15_animating-network-evolutions-with-gganimate/
Other mapping:
check_layout,
completion,
layout_concentric(),
layout_configuration(),
layout_correspondence(),
layout_layered(),
layout_levels(),
layout_matching(),
layout_scaling(),
layout_spatial(),
layout_valence(),
plot_graphr,
plot_graphs
# A dynamic signed network of shifting European alliances 1872-1918,
# split automatically into snapshots of the ties active in each spell.
# Wrapped in \donttest{} because rendering the animation to a .gif is
# slow, not because the code is unsafe to run.
grapht(irps_wwi)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.