R/geom_edge_bundle_force.R
geom_edge_bundle_force.Rd
This geom performs force directed edge bundling to reduce visual clutter.
It uses a self-organizing approach to bundling in which edges are modeled as
flexible springs that can attract each other without the need of a hierarchy.
Be aware that this bundling technique works globally and thus may bundle
edges that is otherwise unrelated together. Care should be taken when
interpreting the resulting visual. An alternative approach to edge bundling
that uses the graph topology is provided by geom_edge_bundle_path()
.
geom_edge_bundle_force(
mapping = NULL,
data = get_edges(),
position = "identity",
arrow = NULL,
n = 100,
force = 1,
n_cycle = 6,
cuts_start = 1,
step = 0.04,
cuts_new = 2,
n_iter = 50,
iter_new = 2/3,
threshold = 0.6,
eps = 1e-08,
lineend = "butt",
linejoin = "round",
linemitre = 1,
label_colour = "black",
label_alpha = 1,
label_parse = FALSE,
check_overlap = FALSE,
angle_calc = "rot",
force_flip = TRUE,
label_dodge = NULL,
label_push = NULL,
show.legend = NA,
...
)
geom_edge_bundle_force2(
mapping = NULL,
data = get_edges("long"),
position = "identity",
arrow = NULL,
n = 100,
force = 1,
n_cycle = 6,
cuts_start = 1,
step = 0.04,
cuts_new = 2,
n_iter = 50,
iter_new = 2/3,
threshold = 0.6,
eps = 1e-08,
lineend = "butt",
linejoin = "round",
linemitre = 1,
label_colour = "black",
label_alpha = 1,
label_parse = FALSE,
check_overlap = FALSE,
angle_calc = "rot",
force_flip = TRUE,
label_dodge = NULL,
label_push = NULL,
show.legend = NA,
...
)
geom_edge_bundle_force0(
mapping = NULL,
data = get_edges(),
position = "identity",
arrow = NULL,
force = 1,
n_cycle = 6,
cuts_start = 1,
step = 0.04,
cuts_new = 2,
n_iter = 50,
iter_new = 2/3,
threshold = 0.6,
eps = 1e-08,
lineend = "butt",
show.legend = NA,
...
)
Set of aesthetic mappings created by ggplot2::aes()
or ggplot2::aes_()
. By default x, y, xend, yend, group and
circular are mapped to x, y, xend, yend, edge.id and circular in the edge
data.
The return of a call to get_edges()
or a data.frame
giving edges in correct format (see details for for guidance on the format).
See get_edges()
for more details on edge extraction.
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The position
argument accepts the following:
The result of calling a position function, such as position_jitter()
.
This method allows for passing extra arguments to the position.
A string naming the position adjustment. To give the position as a
string, strip the function name of the position_
prefix. For example,
to use position_jitter()
, give the position as "jitter"
.
For more information and other ways to specify the position, see the layer position documentation.
Arrow specification, as created by grid::arrow()
.
The number of points to create along the path.
The spring force during bundling
number of iteration cycles
initial number of edge divisions
initial step size
factor for how many new division points to add after a cycle
number of iteration steps per cycle
factor of how to decrease the number of iterations per cycle
threshold for considering two edges to be interacting
tolerance
Line end style (round, butt, square).
Line join style (round, mitre, bevel).
Line mitre limit (number greater than 1).
The colour of the edge label. If NA
it will use
the colour of the edge.
The opacity of the edge label. If NA
it will use
the opacity of the edge.
If TRUE
, the labels will be parsed into expressions
and displayed as described in grDevices::plotmath()
.
If TRUE
, text that overlaps previous text in the
same layer will not be plotted. check_overlap
happens at draw time and in
the order of the data. Therefore data should be arranged by the label
column before calling geom_text()
. Note that this argument is not
supported by geom_label()
.
Either 'none', 'along', or 'across'. If 'none' the label will use the angle aesthetic of the geom. If 'along' The label will be written along the edge direction. If 'across' the label will be written across the edge direction.
Logical. If angle_calc
is either 'along' or 'across'
should the label be flipped if it is on it's head. Default to TRUE
.
A grid::unit()
giving a fixed vertical shift
to add to the label in case of angle_calc
is either 'along' or 'across'
A grid::unit()
giving a fixed horizontal shift
to add to the label in case of angle_calc
is either 'along' or 'across'
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.
FALSE
never includes, and TRUE
always includes.
It can also be a named logical vector to finely select the aesthetics to
display. To include legend keys for all levels, even
when no data exists, use TRUE
. If NA
, all levels are shown in legend,
but unobserved levels are omitted.
Other arguments passed on to layer()
's params
argument. These
arguments broadly fall into one of 4 categories below. Notably, further
arguments to the position
argument, or aesthetics that are required
can not be passed through ...
. Unknown arguments that are not part
of the 4 categories below are ignored.
Static aesthetics that are not mapped to a scale, but are at a fixed
value and apply to the layer as a whole. For example, colour = "red"
or linewidth = 3
. The geom's documentation has an Aesthetics
section that lists the available options. The 'required' aesthetics
cannot be passed on to the params
. Please note that while passing
unmapped aesthetics as vectors is technically possible, the order and
required length is not guaranteed to be parallel to the input data.
When constructing a layer using
a stat_*()
function, the ...
argument can be used to pass on
parameters to the geom
part of the layer. An example of this is
stat_density(geom = "area", outline.type = "both")
. The geom's
documentation lists which parameters it can accept.
Inversely, when constructing a layer using a
geom_*()
function, the ...
argument can be used to pass on parameters
to the stat
part of the layer. An example of this is
geom_area(stat = "density", adjust = 0.5)
. The stat's documentation
lists which parameters it can accept.
The key_glyph
argument of layer()
may also be passed on through
...
. This can be one of the functions described as
key glyphs, to change the display of the layer in the legend.
geom_edge_bundle_force
and geom_edge_bundle_force0
understand the following
aesthetics. Bold aesthetics are automatically set, but can be overwritten.
x
y
xend
yend
edge_colour
edge_width
edge_linetype
edge_alpha
filter
geom_edge_bundle_force2
understand the following aesthetics. Bold aesthetics are
automatically set, but can be overwritten.
x
y
group
edge_colour
edge_width
edge_linetype
edge_alpha
filter
geom_edge_bundle_force
and geom_edge_bundle_force2
furthermore takes the following
aesthetics.
start_cap
end_cap
label
label_pos
label_size
angle
hjust
vjust
family
fontface
lineheight
The position along the path (not computed for the *0 version)
Many geom_edge_* layers comes in 3 flavors depending on the level of control
needed over the drawing. The default (no numeric postfix) generate a number
of points (n
) along the edge and draws it as a path. Each point along
the line has a numeric value associated with it giving the position along the
path, and it is therefore possible to show the direction of the edge by
mapping to this e.g. colour = after_stat(index)
. The version postfixed with a
"2" uses the "long" edge format (see get_edges()
) and makes it
possible to interpolate node parameter between the start and end node along
the edge. It is considerable less performant so should only be used if this
is needed. The version postfixed with a "0" draws the edge in the most
performant way, often directly using an appropriate grob from the grid
package, but does not allow for gradients along the edge.
Often it is beneficial to stop the drawing of the edge before it reaches the
node, for instance in cases where an arrow should be drawn and the arrowhead
shouldn't lay on top or below the node point. geom_edge_* and geom_edge_*2
supports this through the start_cap and end_cap aesthetics that takes a
geometry()
specification and dynamically caps the termini of the
edges based on the given specifications. This means that if
end_cap = circle(1, 'cm')
the edges will end at a distance of 1cm even
during resizing of the plot window.
All geom_edge_*
and geom_edge_*2
have the ability to draw a
label along the edge. The reason this is not a separate geom is that in order
for the label to know the location of the edge it needs to know the edge type
etc. Labels are drawn by providing a label aesthetic. The label_pos can be
used to specify where along the edge it should be drawn by supplying a number
between 0 and 1. The label_size aesthetic can be used to control the size of
the label. Often it is needed to have the label written along the direction
of the edge, but since the actual angle is dependent on the plot dimensions
this cannot be calculated beforehand. Using the angle_calc argument allows
you to specify whether to use the supplied angle aesthetic or whether to draw
the label along or across the edge.
In order to avoid excessive typing edge aesthetic names are
automatically expanded. Because of this it is not necessary to write
edge_colour
within the aes()
call as colour
will
automatically be renamed appropriately.
Holten, D. and Wijk, J.J.V. (2009). Force‐Directed Edge Bundling for Graph Visualization. Computer Graphics Forum (Blackwell Publishing Ltd) 28, no. 3: 983-990. https://doi.org/10.1111/j.1467-8659.2009.01450.x
Other geom_edge_*:
geom_edge_arc()
,
geom_edge_bend()
,
geom_edge_bundle_minimal()
,
geom_edge_bundle_path()
,
geom_edge_density()
,
geom_edge_diagonal()
,
geom_edge_elbow()
,
geom_edge_fan()
,
geom_edge_hive()
,
geom_edge_link()
,
geom_edge_loop()
,
geom_edge_parallel()
,
geom_edge_point()
,
geom_edge_sf()
,
geom_edge_span()
,
geom_edge_tile()
# (not necessarily an insightful use)
ggraph(highschool) +
geom_edge_bundle_force(n_cycle = 2, threshold = 0.4)
#> Using "stress" as default layout