Title: | Automatic Plotting of Many Graphs |
Version: | 0.4.0 |
Date: | 2025-09-09 |
Description: | Visual exploration and presentation of networks should not be difficult. This package includes functions for plotting networks and network-related metrics with sensible and pretty defaults. It includes 'ggplot2'-based plot methods for many popular network package classes. It also includes some novel layout algorithms, and options for straightforward, consistent themes. |
URL: | https://stocnet.github.io/autograph/ |
BugReports: | https://github.com/stocnet/autograph/issues |
License: | MIT + file LICENSE |
Language: | en-GB |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
Depends: | R (≥ 3.6.0), manynet |
Imports: | dplyr (≥ 1.1.0), ggdendro, ggraph, ggplot2, igraph, patchwork, tidygraph |
Suggests: | BiocManager, gganimate, ggforce (≥ 0.5.0), gifski, graphlayouts, methods, testthat (≥ 3.0.0) |
Enhances: | ergm, Rgraphviz, RSiena |
Config/Needs/build: | roxygen2, devtools |
Config/Needs/check: | covr, lintr, spelling |
Config/Needs/website: | pkgdown |
Config/testthat/parallel: | true |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-09-09 16:22:47 UTC; hollway |
Author: | James Hollway |
Maintainer: | James Hollway <james.hollway@graduateinstitute.ch> |
Repository: | CRAN |
Date/Publication: | 2025-09-10 06:40:53 UTC |
autograph: Automatic Plotting of Many Graphs
Description
Visual exploration and presentation of networks should not be difficult. This package includes functions for plotting networks and network-related metrics with sensible and pretty defaults. It includes 'ggplot2'-based plot methods for many popular network package classes. It also includes some novel layout algorithms, and options for straightforward, consistent themes.
Details
For more details, please consult the README and work through the tutorial.
The tutorial can be run locally using run_tute("visualisation")
.
Author(s)
James Hollway
See Also
Useful links:
Consistent palette calls
Description
These functions assist in calling particular parts of a theme's palette.
For example, ag_base()
will return the current theme's base or background
color, and ag_highlight()
will return the color used in that theme to
highlight one or more nodes, lines, or such.
Usage
ag_base()
ag_highlight()
ag_positive()
ag_negative()
ag_qualitative(number)
ag_sequential(number)
ag_divergent(number)
ag_font()
Arguments
number |
Integer of how many category colours to return. |
Value
One or more hexcodes as strings.
Layouts for snapping layouts to a grid
Description
The function uses approximate pattern matching to redistribute coarse layouts on square grid points, while preserving the topological relationships among the nodes (see Inoue et al. 2012).
Usage
depth_first_recursive_search(layout)
References
Inoue, Kentaro, Shinichi Shimozono, Hideaki Yoshida, and Hiroyuki Kurata. 2012. “Application of Approximate Pattern Matching in Two Dimensional Spaces to Grid Layout for Biochemical Network Maps” edited by J. Bourdon. PLoS ONE 7(6):e37739. doi:10.1371/journal.pone.0037739.
Layout algorithms based on configurational positions
Description
Configurational layouts locate nodes at symmetric coordinates to help illustrate particular configurations. Currently configurational layouts are available for 2-6 nodes. The "configuration" layout will choose the appropriate configurational layout automatically.
Usage
layout_configuration(.data, circular = TRUE, times = 1)
layout_tbl_graph_configuration(.data, circular = TRUE, times = 1)
layout_dyad(.data, circular = TRUE, times = 1)
layout_tbl_graph_dyad(.data, circular = TRUE, times = 1)
layout_triad(.data, circular = TRUE, times = 1)
layout_tbl_graph_triad(.data, circular = TRUE, times = 1)
layout_tetrad(.data, circular = TRUE, times = 1)
layout_tbl_graph_tetrad(.data, circular = TRUE, times = 1)
layout_pentad(.data, circular = TRUE, times = 1)
layout_tbl_graph_pentad(.data, circular = TRUE, times = 1)
layout_hexad(.data, circular = TRUE, times = 1)
layout_tbl_graph_hexad(.data, circular = TRUE, times = 1)
Arguments
.data |
Some |
circular |
Logical, required for |
times |
Integer, how many times to run the algorithm.
Required by for |
See Also
Other mapping:
layout_partition
,
plot_graphr
,
plot_graphs
,
plot_grapht
Layered layout
Description
Layered layout
Usage
layout_tbl_graph_layered(.data, center = NULL, circular = FALSE, times = 4)
Arguments
.data |
Some |
center , circular |
Extra parameters required for |
times |
Integer of sweeps that the algorithm will pass through. By default 4. |
Value
Returns a table of coordinates.
Examples
ties <- data.frame(
from = c("A", "A", "B", "C", "D", "F", "F", "E"),
to = c("B", "C", "D", "E", "E", "E", "G", "G"),
stringsAsFactors = FALSE)
coords <- layout_tbl_graph_layered(ties, times = 6)
coords
Matching layout
Description
This layout works to position nodes opposite their matching nodes.
See manynet::to_matching()
for more details on the matching procedure.
Usage
layout_tbl_graph_matching(.data, center = NULL, circular = FALSE, times = 1)
Arguments
.data |
Some |
center , circular , times |
Extra parameters required for |
Value
Returns a table of nodes' x and y coordinates.
Layout algorithms based on bi- or other partitions
Description
These algorithms layout networks based on two or more partitions,
and are recommended for use with graphr()
or {ggraph}
.
Note that these layout algorithms use {Rgraphviz}
,
a package that is only available on Bioconductor.
It will first need to be downloaded using BiocManager::install("Rgraphviz")
.
If it has not already been installed, there is a prompt the first time
these functions are used though.
The "hierarchy" layout layers the first node set along the bottom, and the second node set along the top, sequenced and spaced as necessary to minimise edge overlap. The "alluvial" layout is similar to "hierarchy", but places successive layers horizontally rather than vertically. The "railway" layout is similar to "hierarchy", but nodes are aligned across the layers. The "ladder" layout is similar to "railway", but places successive layers horizontally rather than vertically. The "concentric" layout places a "hierarchy" layout around a circle, with successive layers appearing as concentric circles. The "multilevel" layout places successive layers as multiple levels. The "lineage" layout ranks nodes in Y axis according to values.
Usage
layout_concentric(
.data,
membership,
radius = NULL,
order.by = NULL,
circular = FALSE,
times = 1000
)
layout_tbl_graph_concentric(
.data,
membership,
radius = NULL,
order.by = NULL,
circular = FALSE,
times = 1000
)
layout_multilevel(.data, level, circular = FALSE)
layout_tbl_graph_multilevel(.data, level, circular = FALSE)
layout_lineage(.data, rank, circular = FALSE)
layout_tbl_graph_lineage(.data, rank, circular = FALSE)
layout_hierarchy(.data, center = NULL, circular = FALSE, times = 1000)
layout_tbl_graph_hierarchy(
.data,
center = NULL,
circular = FALSE,
times = 1000
)
layout_alluvial(.data, circular = FALSE, times = 1000)
layout_tbl_graph_alluvial(.data, circular = FALSE, times = 1000)
layout_railway(.data, circular = FALSE, times = 1000)
layout_tbl_graph_railway(.data, circular = FALSE, times = 1000)
layout_ladder(.data, circular = FALSE, times = 1000)
layout_tbl_graph_ladder(.data, circular = FALSE, times = 1000)
Arguments
.data |
Some |
membership |
A node attribute or a vector to draw concentric circles for "concentric" layout. |
radius |
A vector of radii at which the concentric circles should be located for "concentric" layout. By default this is equal placement around an empty centre, unless one (the core) is a single node, in which case this node occupies the centre of the graph. |
order.by |
An attribute label indicating the (decreasing) order for the nodes around the circles for "concentric" layout. By default ordering is given by a bipartite placement that reduces the number of edge crossings. |
circular |
Should the layout be transformed into a radial representation. Only possible for some layouts. Defaults to FALSE. |
times |
Maximum number of iterations, where appropriate |
level |
A node attribute or a vector to hierarchically order levels for "multilevel" layout. |
rank |
A numerical node attribute to place nodes in Y axis according to values for "lineage" layout. |
center |
Further split "hierarchical" layouts by declaring the "center" argument as the "events", "actors", or by declaring a node name in hierarchy layout. Defaults to NULL. |
Source
Diego Diez, Andrew P. Hutchins and Diego Miranda-Saavedra. 2014. "Systematic identification of transcriptional regulatory modules from protein-protein interaction networks". Nucleic Acids Research, 42 (1) e6.
See Also
Other mapping:
layout_configuration()
,
plot_graphr
,
plot_graphs
,
plot_grapht
Examples
#graphr(ison_southern_women, layout = "concentric", membership = "type",
# node_color = "type", node_size = 3)
#graphr(ison_lotr, layout = "multilevel",
# node_color = "Race", level = "Race", node_size = 3)
# ison_adolescents %>%
# mutate(year = rep(c(1985, 1990, 1995, 2000), times = 2),
# cut = node_is_cutpoint(ison_adolescents)) %>%
# graphr(layout = "lineage", rank = "year", node_color = "cut",
# node_size = migraph::node_degree(ison_adolescents)*10)
#graphr(ison_southern_women, layout = "hierarchy", center = "events",
# node_color = "type", node_size = 3)
#graphr(ison_southern_women, layout = "alluvial")
Valence-based layout
Description
Valence-based layout
Usage
layout_valence(
.data,
times = 500,
center = NULL,
circular = FALSE,
repulsion_coef = 1,
attraction_coef = 0.05
)
layout_tbl_graph_valence(
.data,
times = 500,
center = NULL,
circular = FALSE,
repulsion_coef = 1,
attraction_coef = 0.05
)
Arguments
.data |
Some |
times |
Integer of sweeps that the algorithm will pass through. By default 4. |
center , circular |
Extra parameters required for |
repulsion_coef |
Coefficient for global repulsion force. Default is 1. |
attraction_coef |
Coefficient for edge-based attraction/repulsion force. Default is 0.05. |
Examples
edges <- data.frame(
from = c("A", "B", "C", "D"),
to = c("B", "C", "D", "A"),
weight = c(2, 3, 1, 4),
sign = c(1, -1, 1, -1) # 1 = positive, -1 = negative
)
graphr(as_igraph(edges), layout="valence")
Precooked results for demonstrating plotting
Description
These are all pre-cooked results objects, saved here to save time in testing and demonstrating how autograph plots look.
Usage
data(res_migraph_reg)
data(res_migraph_test)
data(res_migraph_diff)
data(res_manynet_diff)
data(siena_gof)
data(siena_influence)
data(siena_selection)
data(monan_conv)
data(monan_gof)
data(ergm_res)
data(ergm_gof)
Format
An object of class netlm
of length 15.
An object of class network_test
of length 9.
An object of class diffs_model
(inherits from data.frame
) with 20 rows and 11 columns.
An object of class diff_model
(inherits from tbl_df
, tbl
, data.frame
) with 4 rows and 10 columns.
An object of class sienaGOF
of length 1.
An object of class influenceTable
(inherits from data.frame
) with 25 rows and 4 columns.
An object of class selectionTable
(inherits from data.frame
) with 25 rows and 4 columns.
An object of class traces.monan
of length 3.
An object of class gof.stats.monan
of length 2.
An object of class ergm
of length 35.
An object of class gof.ergm
(inherits from gof
) of length 30.
Plotting logical marks Plotting numeric measures
Description
These functions plot distributions for node, tie, and network measures,
as defined in the {manynet}
package.
Usage
## S3 method for class 'node_measure'
plot(x, type = c("h", "d"), ...)
## S3 method for class 'tie_measure'
plot(x, type = c("h", "d"), ...)
## S3 method for class 'network_measures'
plot(x, ...)
Arguments
x |
An object of "node_measure", "tie_measure", or "network_measures" class. |
type |
For node and tie measures, whether the plot should be "h" a histogram or "d" a density plot. By default "h". |
... |
Other arguments to be passed on. |
Value
plot.node_measure()
and plot.tie_measure()
returns a histogram
and/or density plot of the distribution of the measure.
plot.network_measures()
returns a plot of the measure traced over
time.
Examples
plot(manynet::node_deg(ison_karateka))
plot(manynet::tie_betweenness(ison_karateka))
Plotting categorical memberships
Description
This plotting method operates on "node_member" class objects from the
{manynet}
package, plotting the dendrogram of their membership.
Usage
## S3 method for class 'node_member'
plot(x, ...)
## S3 method for class 'matrix'
plot(x, ..., membership = NULL)
Arguments
x |
An object of "node_member" class, for example as a result of
running |
... |
Other arguments to be passed on. |
membership |
A "node_member" membership vector. |
Value
plot.node_member()
returns a dendrogram, with labels colored to
indicate the different clusters, and with the optimal cutpoint shown by a
dashed highlight line.
plot.matrix()
returns a plot of an adjacency or incidency matrix,
potentially with the rows and columns reordered to illustrate an additional
membership vector.
Examples
plot(manynet::node_in_walktrap(ison_southern_women, "e"))
plot(as_matrix(ison_adolescents),
membership = node_in_walktrap(ison_adolescents, "e"))
plot(as_matrix(ison_southern_women),
membership = node_in_walktrap(ison_southern_women, "e"))
Plotting tabular motifs
Description
These functions will plot graphs of the motifs used in a vector of results of e.g. a triad census.
Usage
## S3 method for class 'node_motif'
plot(x, ...)
## S3 method for class 'network_motif'
plot(x, ...)
Arguments
x |
An object of "node_motif" class, e.g. resulting from a call to
|
... |
Other arguments to be passed on. |
Value
plot.node_motif()
returns a set of graphs that illustrate the
motifs mentioned in the results from a node_motif function in {manynet}
.
plot.network_motif()
returns a set of graphs that illustrate the
motifs mentioned in the results from a net_motif function in {manynet}
.
Plotting methods for MRQAP models
Description
These plotting methods are for results obtained by fitting an MRQAP
model.
The S3 classes are "netlm" or "netlogit", and so are compatible with the
results from either the {sna}
or {migraph}
packages.
Usage
## S3 method for class 'netlm'
plot(x, ...)
## S3 method for class 'netlogit'
plot(x, ...)
Arguments
x |
An object obtained by fitting an MRQAP model to some data.
For example, |
... |
Further arguments to be passed on to plot. |
Value
A plot showing the location of observed statistics compared to the distribution of statistics from permuted networks.
Examples
# Here's something I cooked up with migraph earlier:
plot(res_migraph_reg)
Plotting diffusion models
Description
Plotting diffusion models
Usage
## S3 method for class 'diff_model'
plot(x, ..., all_steps = TRUE)
## S3 method for class 'diffs_model'
plot(x, ...)
## S3 method for class 'learn_model'
plot(x, ...)
Arguments
x |
A "diff_model" of "diffs_model" class of object.
E.g. as a result from |
... |
Other arguments to be passed. |
all_steps |
Whether all steps should be plotted or just those where there is change in the distributions. |
Value
plot.diff_model()
returns a bar chart of the number of new
infected nodes at each time point, as well as an overlay line plot of the
total of infected
Examples
plot(res_manynet_diff)
plot(res_migraph_diff)
plot(play_learning(ison_networkers, beliefs = runif(net_nodes(ison_networkers))))
Plotting methods for CUG and QAP tests
Description
These plotting methods are for results obtained by testing some statistic against those produced in a reference distribution of conditional uniform graphs or as a quadratic assignment procedure. The S3 class is "network_test".
Usage
## S3 method for class 'network_test'
plot(x, ..., threshold = 0.95, tails = c("two", "one"))
Arguments
x |
An object obtained from a conditional uniform graph or
quadratic assignment procedure test.
For example, |
... |
Other arguments to be passed on. |
threshold |
The empirical threshold to shade in the plot. |
tails |
By default "two" indicating a two-tailed test, but "one" for a one-tailed test is also available. |
Value
A distribution of the simulated or permuted statistics, with 2.5% shaded at each end, and a line highlighting where the observed statistic lies on this distribution.
Examples
# Here's something I cooked up with migraph earlier:
plot(res_migraph_test)
Plotting convergence diagnostics
Description
These plotting methods are for diagnosing the convergence of simulation-based estimation procedures, such as those used in MoNAn and ergm. These plots are useful for identifying whether the estimation procedure has adequately explored the state space and converged to a stable distribution.
Usage
## S3 method for class 'ag_conv'
plot(x, ...)
## S3 method for class 'traces.monan'
plot(x, ...)
## S3 method for class 'mcmc.list'
plot(x, ...)
Arguments
x |
An object of class "traces.monan". |
... |
Additional plotting parameters, currently unused. |
Value
The function shows a line plot tracing the statistics obtained at each simulation step, as well as a density plot showing the distribution of the statistics over the entire simulation.
See Also
Other MoNAn:
plot_gof
Other ergm:
plot_gof
Examples
plot(monan_conv)
plot(ergm_res$sample)
Plotting goodness-of-fit results
Description
These plot methods plot goodness of fit objects created using
RSiena::sienaGOF()
, MoNAn::monanGOF()
, or the 'ergm' package's gof() function.
Internally, the GOF object is translated into a common class (ag_gof
),
which has its own plot method to ensure a consistent look and feel.
It is not expected that users will create ag_gof
class objects themselves.
The plot shows a violin plot of the distribution of statistics from the
simulations, with a boxplot inside the violin to show the interquartile range,
and dashed lines connecting the 5th and 95th percentiles.
The boxplot also shows outliers as crosses.
The observed statistics are shown as points and connected by a line.
The observed statistics are also labelled with their value.
If a p-value is available (as in the case of RSiena::sienaGOF()
),
it is shown beneath the x-axis.
Usage
## S3 method for class 'ag_gof'
plot(x, ...)
## S3 method for class 'gof.stats.monan'
plot(x, cumulative = FALSE, ...)
## S3 method for class 'sienaGOF'
plot(x, cumulative = FALSE, ...)
## S3 method for class 'gof.ergm'
plot(x, cumulative = FALSE, statistic = c("deg", "espart", "dist"), ...)
Arguments
x |
An object of class "sienaGOF", "gof.stats.monan", or "gof.ergm". |
... |
Other parameters to be passed to the plotting function,
for example |
cumulative |
Logical, indicating whether the statistics should be
plotted cumulatively (default FALSE).
This is typically treated in |
statistic |
Character, indicating which statistic to plot.
Since 'ergm' package GOFs include goodness of fit on multiple statistics,
the user must specify which statistic to plot.
Options are |
Details
Since these plots methods are in {autograph}
,
the plots are automatically themed according to the current theme
set using stocnet_theme()
.
The function uses the highlight colour defined in the current theme
to highlight the observed statistics.
The function also uses the base colour defined in the current theme
to draw the violin and box plots.
It is however completely customisable.
While a title is automatically generated so that the graph is informative,
this can be customised by specifying the main
argument in the plotting function,
or added after the fact using {ggplot2}
functions such as
ggtitle()
or labs()
.
The user can choose whether to plot the statistics cumulatively or not.
This is typically handled within RSiena::sienaGOF()
,
but for MoNAn::monanGOF()
and the 'ergm' package's gof() function
the cumulative option is handled here.
The default is to plot the non-cumulative statistics.
This is because the non-cumulative statistics are often more interpretable,
and the cumulative statistics can be obtained by setting cumulative = TRUE
.
The function also checks whether any of the statistics have zero variance across the simulations, and if so, these statistics are not plotted, with a message to the user indicating which statistics were omitted.
Note that these methods overwrite any plot methods for these classes
that may be provided by the original packages.
You may receive such a warning in the console when loading the package.
Please load {autograph}
after these other packages to ensure the plotting
methods included in this package are used,
or specify the package when calling the plotting method directly,
e.g., autograph:::plot.sienaGOF(res_siena_gof)
.
Value
A violin plot showing the distribution of statistics from the simulations and a line joining points showing the observed statistics.
References
Hintze, J. L. and Nelson, R. D. 1998. "Violin plots: A box plot-density trace synergism". The American Statistician, 52:181–184. doi:10.1080/00031305.1998.10480559
See Also
Other MoNAn:
plot_convergence
Other RSiena:
plot_interp
Other ergm:
plot_convergence
Examples
plot(monan_gof)
plot(siena_gof, cumulative = TRUE)
plot(ergm_gof, statistic = "espart")
Easily graph networks with sensible defaults
Description
This function provides users with an easy way to graph (m)any network data for exploration, investigation, inspiration, and communication.
It builds upon {ggplot2}
and {ggraph}
to offer
pretty and extensible graphing solutions.
However, compared to those solutions,
graphr()
contains various algorithms to provide better looking
graphs by default.
This means that just passing the function some network data
will often be sufficient to return a reasonable-looking graph.
The function also makes it easy to modify many of the most
commonly adapted aspects of a graph,
including node and edge size, colour, and shape,
as arguments rather than additional functions that you need to remember.
These can be defined outright, e.g. node_size = 8
, or
in reference to an attribute of the network, e.g. node_size = "wealth"
.
Lastly, graphr()
uses {ggplot2}
-related theme information, so
it is easy to make colour palette and fonts institution-specific and consistent.
See e.g. theme_iheid()
for more.
To learn more about what can be done visually,
try run_tute("Visualisation")
.
Usage
graphr(
.data,
layout,
labels = TRUE,
node_color,
node_shape,
node_size,
node_group,
edge_color,
edge_size,
snap = FALSE,
...,
node_colour,
edge_colour
)
Arguments
.data |
A manynet-consistent object. |
layout |
An igraph, ggraph, or manynet layout algorithm. If not declared, defaults to "triad" for networks with 3 nodes, "quad" for networks with 4 nodes, "stress" for all other one mode networks, or "hierarchy" for two mode networks. For "hierarchy" layout, one can further split graph by declaring the "center" argument as the "events", "actors", or by declaring a node name. For "concentric" layout algorithm please declare the "membership" as an extra argument. The "membership" argument expects either a quoted node attribute present in data or vector with the same length as nodes to draw concentric circles. For "multilevel" layout algorithm please declare the "level" as extra argument. The "level" argument expects either a quoted node attribute present in data or vector with the same length as nodes to hierarchically order categories. If "level" is missing, function will look for 'lvl' node attribute in data. The "lineage" layout ranks nodes in Y axis according to values. For "lineage" layout algorithm please declare the "rank" as extra argument. The "rank" argument expects either a quoted node attribute present in data or vector with the same length as nodes. |
labels |
Logical, whether to print node names as labels if present. |
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. 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. |
node_group |
Node variable to be used for grouping the nodes. It is easiest if this is added as a hull over groups before plotting. Group variables should have a minimum of 3 nodes, if less, number groups will be reduced by merging categories with lower counts into one called "other". |
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. |
snap |
Logical scalar, whether the layout should be snapped to a grid. |
... |
Extra arguments to pass on to the layout algorithm, if necessary. |
Value
A ggplot2::ggplot()
object.
The last plot can be saved to the file system using ggplot2::ggsave()
.
See Also
Other mapping:
layout_configuration()
,
layout_partition
,
plot_graphs
,
plot_grapht
Examples
graphr(ison_adolescents)
ison_adolescents %>%
mutate(color = rep(c("introvert","extrovert"), times = 4),
size = ifelse(node_is_cutpoint(ison_adolescents), 6, 3)) %>%
mutate_ties(ecolor = rep(c("friends", "acquaintances"), times = 5)) %>%
graphr(node_color = "color", node_size = "size",
edge_size = 1.5, edge_color = "ecolor")
Easily graph a set of networks with sensible defaults
Description
This function provides users with an easy way to graph lists of network data for comparison.
It builds upon this package's graphr()
function,
and inherits all the same features and arguments.
See graphr()
for more.
However, it uses the {patchwork}
package to plot the graphs
side by side and, if necessary, in successive rows.
This is useful for lists of networks that represent, for example,
ego or component subgraphs of a network,
or a list of a network's different types of tie or across time.
By default just the first and last network will be plotted,
but this can be overridden by the "waves" parameter.
Where the graphs are of the same network (same nodes), the graphs may share a layout to facilitate comparison. By default, successive graphs will use the layout calculated for the "first" network, but other options include the "last" layout, or a mix, "both", of them.
Usage
graphs(netlist, waves, based_on = c("first", "last", "both"), ...)
Arguments
netlist |
A list of manynet-compatible networks. |
waves |
Numeric, the number of plots to be displayed side-by-side. If missing, the number of plots will be reduced to the first and last when there are more than four plots. This argument can also be passed a vector selecting the waves to plot. |
based_on |
Whether the layout of the joint plots should be based on the "first" or the "last" network, or "both". |
... |
Additional arguments passed to |
Value
Multiple ggplot2::ggplot()
objects displayed side-by-side.
See Also
Other mapping:
layout_configuration()
,
layout_partition
,
plot_graphr
,
plot_grapht
Examples
#graphs(to_egos(ison_adolescents))
#graphs(to_egos(ison_adolescents), waves = 8)
#graphs(to_egos(ison_adolescents), waves = c(2, 4, 6))
#graphs(play_diffusion(ison_adolescents))
Easily animate dynamic networks with sensible defaults
Description
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.
A progress bar is shown if it takes some time to encoding all the .png files into a .gif.
Usage
grapht(
tlist,
keep_isolates = TRUE,
layout,
labels = TRUE,
node_color,
node_shape,
node_size,
edge_color,
edge_size,
...,
node_colour,
edge_colour
)
Arguments
tlist |
The same migraph-compatible network listed according to a time attribute, waves, or slices. |
keep_isolates |
Logical, whether to keep isolate nodes in the graph. TRUE by default. If FALSE, removes nodes from each frame they are isolated in. |
layout |
An igraph, ggraph, or manynet layout algorithm. If not declared, defaults to "triad" for networks with 3 nodes, "quad" for networks with 4 nodes, "stress" for all other one mode networks, or "hierarchy" for two mode networks. For "hierarchy" layout, one can further split graph by declaring the "center" argument as the "events", "actors", or by declaring a node name. For "concentric" layout algorithm please declare the "membership" as an extra argument. The "membership" argument expects either a quoted node attribute present in data or vector with the same length as nodes to draw concentric circles. For "multilevel" layout algorithm please declare the "level" as extra argument. The "level" argument expects either a quoted node attribute present in data or vector with the same length as nodes to hierarchically order categories. If "level" is missing, function will look for 'lvl' node attribute in data. The "lineage" layout ranks nodes in Y axis according to values. For "lineage" layout algorithm please declare the "rank" as extra argument. The "rank" argument expects either a quoted node attribute present in data or vector with the same length as nodes. |
labels |
Logical, whether to print node names as labels if present. |
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. 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. |
... |
Extra arguments to pass on to the layout algorithm, if necessary. |
Value
Shows a .gif image. Assigning the result of the function saves the gif to a temporary folder and the object holds the path to this file.
Source
https://blog.schochastics.net/posts/2021-09-15_animating-network-evolutions-with-gganimate/
See Also
Other mapping:
layout_configuration()
,
layout_partition
,
plot_graphr
,
plot_graphs
Examples
#ison_adolescents %>%
# mutate_ties(year = sample(1995:1998, 10, replace = TRUE)) %>%
# to_waves(attribute = "year", cumulative = TRUE) %>%
# grapht()
#ison_adolescents %>%
# mutate(gender = rep(c("male", "female"), times = 4),
# hair = rep(c("black", "brown"), times = 4),
# age = sample(11:16, 8, replace = TRUE)) %>%
# mutate_ties(year = sample(1995:1998, 10, replace = TRUE),
# links = sample(c("friends", "not_friends"), 10, replace = TRUE),
# weekly_meetings = sample(c(3, 5, 7), 10, replace = TRUE)) %>%
# to_waves(attribute = "year") %>%
# grapht(layout = "concentric", membership = "gender",
# node_shape = "gender", node_color = "hair",
# node_size = "age", edge_color = "links",
# edge_size = "weekly_meetings")
#grapht(play_diffusion(ison_adolescents, seeds = 5))
Plotting effects interpretation
Description
These functions support the interpretation of network and behavior effects
found in stochastic actor-oriented models.
They are S3 plotting methods for objects of class "selectionTable"
or "influenceTable", created using RSiena::selectionTable()
or RSiena::influenceTable()
, respectively.
They plot how the evaluation function for selection or influence
changes based on ego's value and alter's value of some covariate.
This helps to interpret the effect of that covariate on the network dynamics
or behavior dynamics, respectively.
Usage
## S3 method for class 'selectionTable'
plot(x, quad = TRUE, separation = 0, ...)
## S3 method for class 'influenceTable'
plot(x, separation = 0, ...)
Arguments
x |
An object of class "selectionTable" or "influenceTable",
created using |
quad |
When TRUE (the default), a quadratic function
(average and total alter) is plotted.
Use |
separation |
This can be used to make the curves visually distinguishable if they overlap too much without it. An advisable value then is, e.g., 0.01. |
... |
Other arguments to be passed. |
Details
These functions were originally written by Tom Snijders, and adapted
for use in the {autograph}
package.
Value
A plot showing how the selection/influence evaluation function changes based on ego's value and alter's value of some covariate.
Author(s)
Tom Snijders
Thanks to Steffen Triebel and Rene Veenstra for corrections.
References
For plotting selection tables, please consult the RSiena manual, Sections 13.1 and 13.3.
For plotting selection tables, please consult the RSiena manual, Sections 13.2 and 13.4.
See Also
Other RSiena:
plot_gof
Other RSiena:
plot_gof
Examples
plot(siena_selection)
plot(siena_influence)
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- dplyr
- ggplot2
aes
,element_blank
,element_text
,geom_point
,geom_smooth
,ggplot
,ggsave
,ggtitle
,guides
,labs
,scale_colour_hue
,scale_size
,scale_x_continuous
,theme
,theme_grey
,unit
,xlab
,ylab
Matching colors across palettes
Description
Sometimes a palette or particular colours are chosen to symbolise or
represent a particular idea,
such as red for "stop" or green for "go",
or to convey some other interpretation.
Yet institutional palettes do not necessarily include all colours,
which can constrain how interpretable visualisations are under
institutional branding requirements.
match_color()
helps to find the closest matching colours in a given palette
to one or more input colours.
There is also a helper function, is_dark()
, to determine whether a color
is dark or light, which can be useful when deciding whether to use white or
black text on top of a colored background.
Usage
match_color(colors, pal)
is_dark(colors)
Arguments
colors |
One or more hexcodes to match with colors from the palette. |
pal |
Optionally, a vector of hexcodes representing a palette in which to find matches. By default, the current theme's qualitative palette is used. |
Details
This function uses the Euclidean distance of colours in CIELAB space to those of a target palette to find the closes corresponding colours. It also ensures that each input color is matched to a unique color in the palette. If there are more input colors than unique colors in the palette, an error is returned.
By default, the current theme's qualitative palette is used,
but any vector of hexcodes can be passed to the pal
argument.
Value
A vector of hexcodes the length of the first argument.
Examples
match_color("#4575b4")
is_dark(c("#000","#FFF"))
Themed scales for further customization
Description
These functions enable to add color scales to be graphs.
Usage
scale_fill_iheid(direction = 1, ...)
scale_colour_iheid(direction = 1, ...)
scale_color_iheid(direction = 1, ...)
scale_edge_colour_iheid(direction = 1, ...)
scale_edge_color_iheid(direction = 1, ...)
scale_fill_centres(direction = 1, ...)
scale_colour_centres(direction = 1, ...)
scale_color_centres(direction = 1, ...)
scale_edge_colour_centres(direction = 1, ...)
scale_edge_color_centres(direction = 1, ...)
scale_fill_sdgs(direction = 1, ...)
scale_colour_sdgs(direction = 1, ...)
scale_color_sdgs(direction = 1, ...)
scale_edge_colour_sdgs(direction = 1, ...)
scale_edge_color_sdgs(direction = 1, ...)
scale_fill_ethz(direction = 1, ...)
scale_colour_ethz(direction = 1, ...)
scale_color_ethz(direction = 1, ...)
scale_edge_colour_ethz(direction = 1, ...)
scale_edge_color_ethz(direction = 1, ...)
scale_fill_uzh(direction = 1, ...)
scale_colour_uzh(direction = 1, ...)
scale_color_uzh(direction = 1, ...)
scale_edge_colour_uzh(direction = 1, ...)
scale_edge_color_uzh(direction = 1, ...)
scale_fill_rug(direction = 1, ...)
scale_colour_rug(direction = 1, ...)
scale_color_rug(direction = 1, ...)
scale_edge_colour_rug(direction = 1, ...)
scale_edge_color_rug(direction = 1, ...)
Arguments
direction |
Direction for using palette colors. |
... |
Extra arguments passed to |
Examples
#ison_brandes %>%
#mutate(core = migraph::node_is_core(ison_brandes)) %>%
#graphr(node_color = "core") +
#scale_color_iheid()
#graphr(ison_physicians[[1]], edge_color = "type") +
#scale_edge_color_ethz()
Setting a consistent theme for all plots
Description
This function enables plots to be quickly, easily and consistently themed. This is achieved by setting a theme option, usually at the start of an R session, that enables the palette to be used for all autograph-consistent plotting methods. This includes thematic colours for backgrounds, highlights, sequential, divergent and categorical colour schemes. The function sets these palettes to options that are then used by the various plotting functions.
If no theme is specified (i.e. the function is called without argument),
the current theme is reported.
The default theme is "default".
This theme uses a white background, blue and red for
highlighting, and a blue-white-red divergent palette.
The themes can be changed at any time by calling stocnet_theme()
or its alias set_stocnet_theme()
with a different theme name.
Other themes include those based on the colour schemes of various universities, including ETH Zurich, UZH, UNIBE, RUG, and Oxford. Other themes include "bw" for black and white, "crisp" for a high-contrast black and white theme, "neon" for a dark theme with neon highlights, and "rainbow" for a colourful theme. Most themes are designed to be colour-blind safe.
Usage
stocnet_theme(theme = NULL)
set_stocnet_theme(theme = NULL)
Arguments
theme |
String naming a theme. By default "default". The following themes are currently available: default, bw, crisp, neon, iheid, ethz, uzh, rug, unibe, oxf, unige, cmu, rainbow. This string can be capitalised or not. |
Value
This function sets the theme and palette(s) to be used across all stocnet packages. The palettes are written to options and held there.
Fonts
Some themes also set a preferred font for use in plots,
if available on the system (a check is performed).
In some cases, this includes a vector of options to try in sequence.
If none of the preferred fonts are available, a sans-serif font is used.
If you receive a warning about a missing font when setting a theme,
try installing one of the preferred fonts or make sure that the font is
available to R using extrafont::font_import()
and extrafont::loadfont()
Examples
stocnet_theme("default")
plot(manynet::node_degree(ison_karateka))
stocnet_theme("rug")
plot(manynet::node_degree(ison_karateka))