| animate | R Documentation |
Draws the network bin by bin over the measurement grid and writes the
frames to an animated GIF or a video. The grid is the same four arguments
every measuring verb takes, so an animation shows exactly what
snapshots() tabulates and what plot(dn, type = "snapshots") draws as a
filmstrip, with the bins joined by motion.
animate(
dn,
start = NULL,
end = NULL,
step = NULL,
window = NULL,
sessions = c("bounded", "collapse"),
layout = "spring",
measure = NULL,
tween = 6L,
fps = 12,
file = tempfile(fileext = ".gif"),
loop = TRUE,
width = 800L,
height = 800L,
res = 120,
palette = "okabe",
tie_states = TRUE,
timeline = TRUE,
absent = c("fade", "away", "hide"),
isolates = c("fade", "show", "hide"),
ease = c("dwell", "continuous"),
max_displacement = 0.08,
anchor_strength = 1,
layout_args = list(),
seed = 42L,
...
)
dn |
A temporal network from |
start, end, step, window |
The measurement grid, as in |
sessions |
How to treat sessions, as in |
layout |
|
measure |
What node size follows. |
tween |
Frames drawn per bin. One positive whole number, |
fps |
Frames per second. One positive number, |
file |
Path to write to, ending in |
loop |
For a GIF: |
width, height |
Frame size in pixels, |
res |
Resolution passed to |
palette |
Palette specification, as in |
tie_states |
Whether to draw forming, persisting and dissolving ties
differently. |
timeline |
Whether to draw the timeline strip. |
absent |
How a vertex is drawn in a bin where it is not present.
|
isolates |
How a vertex that is present but has no tie in a bin is
drawn. |
ease |
|
max_displacement |
How far a vertex may move between bins under
|
anchor_strength |
How strongly a vertex is pulled back towards its
previous position under |
layout_args |
A named list of further arguments for
|
seed |
Seed for the spring layouts, so |
... |
Passed to |
Frames. Each bin is drawn tween times. Between one bin and the next
the vertices glide to their new positions, a tie that is about to appear
fades in and one that is about to vanish fades out, and a vertex whose
measure changes grows or shrinks. Under ease = "dwell", the default,
the motion follows the smoothstep curve, so each bin holds still before
it starts to change and the bins can be read one by one. Under
ease = "continuous" nothing holds still: positions follow a Catmull-Rom
spline through the bins, so a vertex moving across several bins traces
one smooth path, and fades are linear. tween = 1 gives one frame per
bin with hard cuts. A film that feels episodic usually has a grid whose
bins do not overlap; a sliding window, step smaller than window,
smooths the data itself, since a tie then persists across several bins.
Layouts. Under every layout but "relaxed" a vertex keeps one position
for the whole animation, so the only thing that moves is the ties; those
are the layouts to read structure from. "spring", the default, lays out
the union of every frame once with cograph::layout_spring(), so pairs
that met often sit close. "circle" and "oval" are rings, in vertex
order. "groups" puts each partition on its own ring and needs a network
built with groups = . "relaxed" lays each frame out again, seeded from
the previous one and held near it by max_displacement and
anchor_strength, then smooths every vertex's path with a centred
triangular kernel over one bin each side; clusters can form and dissolve
without vertices jumping, and no vertex moves further than
max_displacement between consecutive bins. Each relaxed frame is framed
by its active vertices: a vertex that is absent or has no tie in the bin
is held at the border of that frame rather than drifting outward under
repulsion, which would shrink the picture. layout_args tunes the spring
layout for both. A data frame with columns name (or node), x and
y fixes the positions yourself.
What is drawn. Tie width follows weight on one scale fixed across the
whole animation, so a tie of the same weight has the same width in a quiet
frame and a busy one. With tie_states = TRUE a tie forming during a
transition is dotted and green, one persisting is solid and grey, and one
dissolving is dashed and vermilion, so the distinction survives without
colour. With measure given, node size follows that measure, again on
one scale across every frame, with the area of the circle proportional to
the measure's position in its range; see the argument for the three forms
it takes.
Absence and idleness. A vertex that is not present in a bin, under
declared vertex activity or observation bounds, is drawn as absent
says: faded in place, parked out of sight at the edge of the layout and
gliding in when it arrives and out when it leaves, or hidden in place. A
network built without vertex activity has every vertex present in every
bin; set_vertex_spells(dn, "ties") declares each vertex present from
its first tie to its last. A vertex that is present but has no tie in a
bin is drawn as isolates says. With timeline = TRUE a strip under the
network shows the grid with a marker at the current time and the key to
the drawing.
Files. The extension of file chooses the encoder: .gif is written
by the gifski package, .mp4 and .webm by the av package. A video needs
even pixel dimensions. Writing the file is the point of the verb, but the
tidy bin table is still what comes back, so the animation can be described
without opening it.
An object of class "dynet_animation": a tidy data frame with one
row per bin and columns bin, frame (the first rendered frame of the
bin), time (the bin's label on the network's time scale),
window_start and window_end (its bounds), nodes (vertices present),
idle (of those, vertices with no tie), ties (ties drawn), forming (ties not active in the previous bin, NA
for the first), dissolving (ties not active in the next bin, NA for
the last), and file (the same on every row). These are counts of what
the picture shows, not the risk-set accounting of events(). The
rendered-frame schedule is available through
as.data.frame(x, what = "frames"). Returned invisibly, since writing
the file is the verb's purpose.
Raises dynet_unknown_format for a file extension other than .gif,
.mp4 or .webm; dynet_needs_gifski or dynet_needs_av when the
encoder that extension needs is not installed; dynet_needs_cograph when
cograph is not; dynet_empty_result when the grid holds no bin that can be
drawn; dynet_unknown_attribute for layout = "groups" on a network
without a partition or a labels naming no vertex attribute;
dynet_missing_column and dynet_unknown_node for a
coordinate table that is incomplete; dynet_unknown_measure for a
measure that is neither a measure centrality_series() offers nor a
numeric vertex attribute, and whatever centrality_series() raises for one it
refuses; dynet_bad_input for a centrality_series() result that is not
node-level or lands on none of the bins, and a warning of class
dynet_partial_measure when it lands on only some; and dynet_bad_input for a non-positive
fps, tween, width, height or res, an odd video size, a loop
that is neither logical nor a positive whole number, or a negative
max_displacement or anchor_strength.
snapshots() for the same grid as a table, plot.dynet() with
type = "snapshots" for it as a static filmstrip, and centrality_series()
for the measures node size can follow.
if (requireNamespace("gifski", quietly = TRUE) &&
requireNamespace("cograph", quietly = TRUE)) {
dn <- dynet(school_contacts)
frames <- animate(dn = dn, end = 8, step = 4, window = 4, tween = 2)
frames
summary(frames)
}
if (requireNamespace("av", quietly = TRUE) &&
requireNamespace("cograph", quietly = TRUE)) {
dn <- dynet(school_contacts)
file <- tempfile(fileext = ".mp4")
video <- animate(dn = dn, end = 8, step = 4, tween = 2, measure = "degree", file = file)
summary(video)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.