| plot_graphr | R Documentation |
This function provides users with an easy way to graph (m)any network data for exploration, investigation, inspiration, and communication.
graphr() builds upon {ggplot2} and {ggraph} to offer
pretty, easy, and extensible graphing solutions.
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").
graphr(
.data,
layout = NULL,
labels = TRUE,
node_color,
node_shape,
node_size,
node_group,
edge_color,
edge_size,
isolates = c("legend", "caption", "keep"),
layout_snap = FALSE,
label_repel = TRUE,
edge_bundle = FALSE,
edge_arrows = NULL,
backbone = NULL,
...,
node_colour,
edge_colour,
snap,
label_dist
)
.data |
A manynet-consistent object. |
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.
Where a length-one string could mean more than one of these,
a node attribute is preferred to a measure, and a measure to a node name.
A single number is always read as a depth of ranks rather than as one
node's position, so a lone node is best named, as in |
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. |
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".
A membership vector can also be given here.
Where nodes belong to several groups at once, as they can to several
cliques, give a membership matrix instead: one row for each node,
one column for each group, and a one wherever the node belongs to
the group. One hull is then drawn for each column, and the hulls
overlap where the groups do.
A measure that returns such a matrix, such as
|
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 |
Character scalar, how to treat isolates.
"keep" will keep isolates in the graph as they are.
"legend" (default) will remove isolates from the graph but note them in the legend.
"caption" will remove isolates from the graph but note them in the caption.
If there are no isolates, this argument will be ignored.
The "lineage" layout defaults to "keep" instead, since it gives every
node a place in its layers, such as a year;
an |
layout_snap |
Logical scalar, whether the layout should be snapped to a grid. Where the network repeats a structure, as a lattice does, the two steps it repeats are mapped onto the axes, which draws it as a rectangle of rows and columns. Where it does not, each node moves to the nearest vacant grid point. Layouts that already carry meaning in their coordinates, such as "layered" or "scaling", are left as they are. |
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_bundle |
Edge bundling, off by default ( |
edge_arrows |
Whether, and at what size, to draw arrowheads on the ties
of a directed network.
By default ( |
backbone |
How to treat the network's backbone: the ties that a local
null model keeps, because they carry more weight, or sit in more
triangles, than chance alone would put there.
Where a backbone is used, those ties are drawn as the shortest, so that
the layout pulls apart the groups they hold together, and every tie is
still drawn, with the ties the filter does not keep faded well back.
This is what to reach for when a network is dense enough to draw as a
hairball.
By default ( |
... |
Extra arguments to pass on to the layout algorithm, if necessary. |
snap, label_dist |
Deprecated. Use |
A ggplot2::ggplot() object.
The last plot can be saved to the file system using ggplot2::ggsave().
Other mapping:
check_layout,
completion,
layout_concentric(),
layout_configuration(),
layout_correspondence(),
layout_layered(),
layout_levels(),
layout_matching(),
layout_scaling(),
layout_spatial(),
layout_valence(),
plot_graphs,
plot_grapht
graphr(ison_adolescents)
ison_adolescents |>
mutate_nodes(color = rep(c("introvert","extrovert"), times = 4),
size = c(3, 6, 3, 3, 3, 6, 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")
graphr(ison_southern_women, labels = TRUE, label_repel = 10)
# Label a selection of the nodes rather than all of them
graphr(ison_southern_women, labels = 2)
graphr(ison_adolescents, labels = c("Alice", "Betty"))
graphr(ison_southern_women, labels = TRUE, label_repel = FALSE)
graphr(ison_karateka, label_repel = "outside")
graphr(ison_southern_women, labels = "betweenness")
graphr(manynet::generate_random(40, 0.1), edge_bundle = TRUE)
# Larger arrowheads than the width of the ties would give, or none at all
graphr(ison_networkers, edge_arrows = 4)
graphr(ison_networkers, edge_arrows = FALSE)
graphr(manynet::generate_random(80, 0.2), backbone = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.