Title: | Additional Layout Algorithms for Network Visualizations |
---|---|
Description: | Several new layout algorithms to visualize networks are provided which are not part of 'igraph'. Most are based on the concept of stress majorization by Gansner et al. (2004) <doi:10.1007/978-3-540-31843-9_25>. Some more specific algorithms allow the user to emphasize hidden group structures in networks or focus on specific nodes. |
Authors: | David Schoch [aut, cre] |
Maintainer: | David Schoch <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.1 |
Built: | 2024-11-18 14:34:18 UTC |
Source: | https://github.com/schochastics/graphlayouts |
annotate concentric circles
annotate_circle(cent, col = "#00BFFF", format = "", pos = "top", text_size = 3)
annotate_circle(cent, col = "#00BFFF", format = "", pos = "top", text_size = 3)
cent |
centrality scores used for layout |
col |
color of text |
format |
either empty string or 'scientific' |
pos |
position of text ('top' or 'bottom') |
text_size |
font size for annotations |
this function is best used with layout_with_centrality together with draw_circle.
annotated concentric circles around origin
library(igraph) g <- sample_gnp(10, 0.4) ## Not run: library(ggraph) ggraph(g, layout = "centrality", centrality = closeness(g)) + draw_circle(use = "cent") + annotate_circle(closeness(g), pos = "bottom", format = "scientific") + geom_edge_link() + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() + coord_fixed() ## End(Not run)
library(igraph) g <- sample_gnp(10, 0.4) ## Not run: library(ggraph) ggraph(g, layout = "centrality", centrality = closeness(g)) + draw_circle(use = "cent") + annotate_circle(closeness(g), pos = "bottom", format = "scientific") + geom_edge_link() + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() + coord_fixed() ## End(Not run)
Draw concentric circles
draw_circle(col = "#00BFFF", use = "focus", max.circle)
draw_circle(col = "#00BFFF", use = "focus", max.circle)
col |
color of circles |
use |
one of 'focus' or 'cent' |
max.circle |
if use = 'focus' specifies the number of circles to draw |
this function is best used with a concentric layout such as layout_with_focus and layout_with_centrality.
concentric circles around origin
library(igraph) g <- sample_gnp(10, 0.4) ## Not run: library(ggraph) ggraph(g, layout = "centrality", centrality = degree(g)) + draw_circle(use = "cent") + geom_edge_link() + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() + coord_fixed() ## End(Not run)
library(igraph) g <- sample_gnp(10, 0.4) ## Not run: library(ggraph) ggraph(g, layout = "centrality", centrality = degree(g)) + draw_circle(use = "cent") + geom_edge_link() + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() + coord_fixed() ## End(Not run)
functions to manipulate a graph
reorder_edges(g, attr, desc = TRUE)
reorder_edges(g, attr, desc = TRUE)
g |
igraph object |
attr |
edge attribute name used to sort edges |
desc |
logical. sort in descending (default) or ascending order |
reorder_edges()
allows to reorder edges according to an attribute so that edges are
drawn in the given order.
manipulated graph
David Schoch
library(igraph) g <- sample_gnp(10, 0.5) E(g)$attr <- 1:ecount(g) gn <- reorder_edges(g,"attr")
library(igraph) g <- sample_gnp(10, 0.5) E(g)$attr <- 1:ecount(g) gn <- reorder_edges(g,"attr")
Metro map layout based on multicriteria optimization
layout_as_metromap(object, xy, l = 2, gr = 0.0025, w = rep(1, 5), bsize = 5)
layout_as_metromap(object, xy, l = 2, gr = 0.0025, w = rep(1, 5), bsize = 5)
object |
original graph |
xy |
initial layout of the original graph |
l |
desired multiple of grid point spacing. (l*gr determines desired edge length) |
gr |
grid spacing. (l*gr determines desired edge length) |
w |
weight vector for criteria (see details) |
bsize |
number of grid points a station can move away rom its original position |
The function optimizes the following five criteria using a hill climbing algorithm:
Angular Resolution Criterion: The angles of incident edges at each station should be maximized, because if there is only a small angle between any two adjacent edges, then it can become difficult to distinguish between them
Edge Length Criterion: The edge lengths across the whole map should be approximately equal to ensure regular spacing between stations. It is based on the preferred multiple, l, of the grid spacing, g. The purpose of the criterion is to penalize edges that are longer than or shorter than lg.
Balanced Edge Length Criterion: The length of edges incident to a particular station should be similar
Line Straightness Criterion: (not yet implemented) Edges that form part of a line should, where possible, be co-linear either side of each station that the line passes through
Octilinearity Criterion: Each edge should be drawn horizontally, vertically, or diagonally at 45 degree, so we penalize edges that are not at a desired angle
new coordinates for stations
David Schoch
Stott, Jonathan, et al. "Automatic metro map layout using multicriteria optimization." IEEE Transactions on Visualization and Computer Graphics 17.1 (2010): 101-114.
# the algorithm has problems with parallel edges library(igraph) g <- simplify(metro_berlin) xy <- cbind(V(g)$lon, V(g)$lat) * 100 # the algorithm is not very stable. try playing with the parameters ## Not run: xy_new <- layout_as_metromap(g, xy, l = 2, gr = 0.5, w = c(100, 100, 1, 1, 100), bsize = 35) ## End(Not run)
# the algorithm has problems with parallel edges library(igraph) g <- simplify(metro_berlin) xy <- cbind(V(g)$lon, V(g)$lat) * 100 # the algorithm is not very stable. try playing with the parameters ## Not run: xy_new <- layout_as_metromap(g, xy, l = 2, gr = 0.5, w = c(100, 100, 1, 1, 100), bsize = 35) ## End(Not run)
emphasizes a hidden group structure if it exists in the graph. Calculates a layout for a sparsified network only including the most embedded edges. Deleted edges are added back after the layout is calculated.
layout_as_backbone(g, keep = 0.2, backbone = TRUE) layout_igraph_backbone(g, keep = 0.2, backbone = TRUE, circular)
layout_as_backbone(g, keep = 0.2, backbone = TRUE) layout_igraph_backbone(g, keep = 0.2, backbone = TRUE, circular)
g |
igraph object |
keep |
fraction of edges to keep during backbone calculation |
backbone |
logical. Return edge ids of the backbone (Default: TRUE) |
circular |
not used |
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
list of xy coordinates and vector of edge ids included in the backbone
Nocaj, A., Ortmann, M., & Brandes, U. (2015). Untangling the hairballs of multi-centered, small-world online social media networks. Journal of Graph Algorithms and Applications: JGAA, 19(2), 595-618.
library(igraph) g <- sample_islands(9, 20, 0.4, 9) g <- simplify(g) V(g)$grp <- as.character(rep(1:9, each = 20)) bb <- layout_as_backbone(g, keep = 0.4) # add backbone links as edge attribute E(g)$col <- FALSE E(g)$col[bb$backbone] <- TRUE
library(igraph) g <- sample_islands(9, 20, 0.4, 9) g <- simplify(g) V(g)$grp <- as.character(rep(1:9, each = 20)) bb <- layout_as_backbone(g, keep = 0.4) # add backbone links as edge attribute E(g)$col <- FALSE E(g)$col[bb$backbone] <- TRUE
arranges nodes in concentric circles according to a centrality index.
layout_with_centrality( g, cent, scale = TRUE, iter = 500, tol = 1e-04, tseq = seq(0, 1, 0.2) ) layout_igraph_centrality( g, cent, scale = TRUE, iter = 500, tol = 1e-04, tseq = seq(0, 1, 0.2), circular )
layout_with_centrality( g, cent, scale = TRUE, iter = 500, tol = 1e-04, tseq = seq(0, 1, 0.2) ) layout_igraph_centrality( g, cent, scale = TRUE, iter = 500, tol = 1e-04, tseq = seq(0, 1, 0.2), circular )
g |
igraph object |
cent |
centrality scores |
scale |
logical. should centrality scores be scaled to |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
tseq |
numeric vector. increasing sequence of coefficients to combine regular stress and constraint stress. See details. |
circular |
not used |
The function optimizes a convex combination of regular stress and a constrained stress function which forces
nodes to be arranged on concentric circles. The vector tseq
is the sequence of parameters used for the convex combination.
In iteration i of the algorithm is used to combine regular and constraint stress as
. The sequence must be increasing, start at zero and end at one. The default setting should be a good choice for most graphs.
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
matrix of xy coordinates
Brandes, U., & Pich, C. (2011). More flexible radial layout. Journal of Graph Algorithms and Applications, 15(1), 157-173.
library(igraph) g <- sample_gnp(10, 0.4) ## Not run: library(ggraph) ggraph(g, layout = "centrality", centrality = closeness(g)) + draw_circle(use = "cent") + geom_edge_link0() + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() + coord_fixed() ## End(Not run)
library(igraph) g <- sample_gnp(10, 0.4) ## Not run: library(ggraph) ggraph(g, layout = "centrality", centrality = closeness(g)) + draw_circle(use = "cent") + geom_edge_link0() + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() + coord_fixed() ## End(Not run)
arranges nodes in concentric circles according to a centrality index and keeping groups within a angle range
layout_with_centrality_group(g, cent, group, shrink = 10, ...) layout_igraph_centrality_group(g, cent, group, shrink = 10, circular, ...)
layout_with_centrality_group(g, cent, group, shrink = 10, ...) layout_igraph_centrality_group(g, cent, group, shrink = 10, circular, ...)
g |
igraph object |
cent |
centrality scores |
group |
vector indicating grouping of nodes |
shrink |
shrink the reserved angle range for a group to increase the gaps between groups |
... |
additional arguments to layout_with_centrality The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout. |
circular |
not used |
matrix of xy coordinates
library(igraph)
library(igraph)
force-directed graph layout based on stress majorization with variable constrained
layout_with_constrained_stress( g, coord, fixdim = "x", weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 ) layout_igraph_constrained_stress( g, coord, fixdim = "x", weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30, circular )
layout_with_constrained_stress( g, coord, fixdim = "x", weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 ) layout_igraph_constrained_stress( g, coord, fixdim = "x", weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30, circular )
g |
igraph object |
coord |
numeric vector. fixed coordinates for dimension specified in |
fixdim |
string. which dimension should be fixed. Either "x" or "y". |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
mds |
should an MDS layout be used as initial layout (default: TRUE) |
bbox |
constrain dimension of output. Only relevant to determine the placement of disconnected graphs |
circular |
not used |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
matrix of xy coordinates
Gansner, E. R., Koren, Y., & North, S. (2004). Graph drawing by stress majorization. In International Symposium on Graph Drawing (pp. 239-250). Springer, Berlin, Heidelberg.
force-directed graph layout based on stress majorization with variable constrained in 3D
layout_with_constrained_stress3D( g, coord, fixdim = "x", weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 )
layout_with_constrained_stress3D( g, coord, fixdim = "x", weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 )
g |
igraph object |
coord |
numeric vector. fixed coordinates for dimension specified in |
fixdim |
string. which dimension should be fixed. Either "x", "y" or "z". |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
mds |
should an MDS layout be used as initial layout (default: TRUE) |
bbox |
constrain dimension of output. Only relevant to determine the placement of disconnected graphs |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
This function does not come with direct support for igraph or ggraph.
matrix of xyz coordinates
Gansner, E. R., Koren, Y., & North, S. (2004). Graph drawing by stress majorization. In International Symposium on Graph Drawing (pp. 239-250). Springer, Berlin, Heidelberg.
Create layouts for longitudinal networks.
layout_as_dynamic(gList, weights = NA, alpha = 0.5, iter = 500, tol = 1e-04)
layout_as_dynamic(gList, weights = NA, alpha = 0.5, iter = 500, tol = 1e-04)
gList |
list of igraph objects. Each network must contain the same set of nodes. |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
alpha |
weighting of reference layout. See details. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
The reference layout is calculated based on the union of all graphs. The parameter alpha controls the influence of the reference layout. For alpha=1, only the reference layout is used and all graphs have the same layout. For alpha=0, the stress layout of each individual graph is used. Values in-between interpolate between the two layouts.
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
list of coordinates for each graph
Brandes, U. and Indlekofer, N. and Mader, M. (2012). Visualization methods for longitudinal social networks and stochastic actor-oriented modeling. Social Networks 34 (3) 291-308
library(igraph) g1 <- sample_gnp(20, 0.2) g2 <- sample_gnp(20, 0.2) g3 <- sample_gnp(20, 0.2) xy <- layout_as_dynamic(list(g1, g2, g3)) # layout for first network xy[[1]]
library(igraph) g1 <- sample_gnp(20, 0.2) g2 <- sample_gnp(20, 0.2) g3 <- sample_gnp(20, 0.2) xy <- layout_as_dynamic(list(g1, g2, g3)) # layout for first network xy[[1]]
force-directed graph layout based on stress majorization with fixed coordinates for some nodes
layout_with_fixed_coords( g, coords, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 ) layout_igraph_fixed_coords( g, coords, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30, circular )
layout_with_fixed_coords( g, coords, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 ) layout_igraph_fixed_coords( g, coords, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30, circular )
g |
igraph object |
coords |
numeric n x 2 matrix, where n is the number of nodes. values are either NA or fixed coordinates. coordinates are only calculated for the NA values. |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
mds |
should an MDS layout be used as initial layout (default: TRUE) |
bbox |
constrain dimension of output. Only relevant to determine the placement of disconnected graphs |
circular |
not used |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
matrix of xy coordinates
library(igraph) set.seed(12) g <- sample_bipartite(10, 5, "gnp", 0.5) fxy <- cbind(c(rep(0, 10), rep(1, 5)), NA) xy <- layout_with_fixed_coords(g, fxy)
library(igraph) set.seed(12) g <- sample_bipartite(10, 5, "gnp", 0.5) fxy <- cbind(c(rep(0, 10), rep(1, 5)), NA) xy <- layout_with_fixed_coords(g, fxy)
arrange nodes in concentric circles around a focal node according to their distance from the focus.
layout_with_focus(g, v, weights = NA, iter = 500, tol = 1e-04) layout_igraph_focus(g, v, weights = NA, iter = 500, tol = 1e-04, circular)
layout_with_focus(g, v, weights = NA, iter = 500, tol = 1e-04) layout_igraph_focus(g, v, weights = NA, iter = 500, tol = 1e-04, circular)
g |
igraph object |
v |
id of focal node to be placed in the center |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
circular |
not used |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
a list containing xy coordinates and the distances to the focal node
Brandes, U., & Pich, C. (2011). More flexible radial layout. Journal of Graph Algorithms and Applications, 15(1), 157-173.
layout_focus_group The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
library(igraph) g <- sample_gnp(10, 0.4) coords <- layout_with_focus(g, v = 1) coords
library(igraph) g <- sample_gnp(10, 0.4) coords <- layout_with_focus(g, v = 1) coords
arrange nodes in concentric circles around a focal node according to their distance from the focus and keep predefined groups in the same angle range.
layout_with_focus_group( g, v, group, shrink = 10, weights = NA, iter = 500, tol = 1e-04 ) layout_igraph_focus_group( g, v, group, shrink = 10, weights = NA, iter = 500, tol = 1e-04, circular )
layout_with_focus_group( g, v, group, shrink = 10, weights = NA, iter = 500, tol = 1e-04 ) layout_igraph_focus_group( g, v, group, shrink = 10, weights = NA, iter = 500, tol = 1e-04, circular )
g |
igraph object |
v |
id of focal node to be placed in the center |
group |
vector indicating grouping of nodes |
shrink |
shrink the reserved angle range for a group to increase the gaps between groups |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
circular |
not used |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
matrix of xy coordinates
layout_focus The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'.
library(igraph) g <- sample_islands(4, 5, 0.8, 2) grp <- as.character(rep(1:4, each = 5)) layout_with_focus_group(g, v = 1, group = grp, shrink = 10)
library(igraph) g <- sample_islands(4, 5, 0.8, 2) grp <- as.character(rep(1:4, each = 5)) layout_with_focus_group(g, v = 1, group = grp, shrink = 10)
functions to manipulate an existing layout
layout_rotate(xy, angle) layout_mirror(xy, axis = "vertical")
layout_rotate(xy, angle) layout_mirror(xy, axis = "vertical")
xy |
graph layout |
angle |
angle for rotation |
axis |
mirror horizontal or vertical |
These functions are mostly useful for deterministic layouts such as layout_with_stress
manipulated matrix of xy coordinates
David Schoch
library(igraph) g <- sample_gnp(50, 0.3) xy <- layout_with_stress(g) # rotate 90 degrees xy <- layout_rotate(xy, 90) # flip horizontally xy <- layout_mirror(xy, "horizontal")
library(igraph) g <- sample_gnp(50, 0.3) xy <- layout_with_stress(g) # rotate 90 degrees xy <- layout_rotate(xy, 90) # flip horizontally xy <- layout_mirror(xy, "horizontal")
Layout algorithm to visualize multilevel networks
layout_as_multilevel( g, type = "all", FUN1, FUN2, params1 = NULL, params2 = NULL, ignore_iso = TRUE, project2D = TRUE, alpha = 35, beta = 45 ) layout_igraph_multilevel( g, type = "all", FUN1, FUN2, params1 = NULL, params2 = NULL, ignore_iso = TRUE, alpha = 35, beta = 45, circular )
layout_as_multilevel( g, type = "all", FUN1, FUN2, params1 = NULL, params2 = NULL, ignore_iso = TRUE, project2D = TRUE, alpha = 35, beta = 45 ) layout_igraph_multilevel( g, type = "all", FUN1, FUN2, params1 = NULL, params2 = NULL, ignore_iso = TRUE, alpha = 35, beta = 45, circular )
g |
igraph object. Must have a vertex attribute "lvl" which is 1 or 2. |
type |
one of "all", "separate","fix1" or "fix2". see details |
FUN1 |
if type="separate", the layout function to be used for level 1 |
FUN2 |
if type="separate", the layout function to be used for level 2 |
params1 |
named list of parameters for FUN1 |
params2 |
named list of parameters for FUN2 |
ignore_iso |
treatment of isolates within levels. see details |
project2D |
logical. Defaults to TRUE (project to 2D). |
alpha |
angle for isometric projection between 0 and 90 |
beta |
angle for isometric projection between 0 and 90 |
circular |
not used |
The algorithm internally computes a 3D layout where each level is in a separate y-plane.
The layout is then projected into 2D via an isometric mapping, controlled by the parameters
alpha
and beta
. It may take some adjusting to alpha
and beta
to find a good perspective.
If type="all", the layout is computed at once for the complete network.
For type="separate", two user specified layout algorithms (FUN1
and FUN2
) are used for the levels.
The named lists param1
and param2
can be used to set parameters for FUN1
and FUN2
.
This option helpful for situations where different structural features of the levels should be emphasized.
For type="fix1" and type="fix2" only one of the level layouts is fixed. The other one is calculated by optimizing the inter level ties, such that they are drawn (almost) vertical.
The ignore_iso
parameter controls the handling of isolates. If TRUE, nodes without inter level edges are ignored during the layout process
and added at the end. If FALSE they are left unchanged
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'.
matrix of xy coordinates
library(igraph) data("multilvl_ex") # compute a layout for the whole network xy <- layout_as_multilevel(multilvl_ex, type = "all", alpha = 25, beta = 45) # compute a layout for each level separately and combine them xy <- layout_as_multilevel(multilvl_ex, type = "separate", FUN1 = layout_as_backbone, FUN2 = layout_with_stress, alpha = 25, beta = 45 )
library(igraph) data("multilvl_ex") # compute a layout for the whole network xy <- layout_as_multilevel(multilvl_ex, type = "all", alpha = 25, beta = 45) # compute a layout for each level separately and combine them xy <- layout_as_multilevel(multilvl_ex, type = "separate", FUN1 = layout_as_backbone, FUN2 = layout_with_stress, alpha = 25, beta = 45 )
similar to layout_with_mds but uses only a small set of pivots for MDS. Considerably faster than MDS and thus applicable for larger graphs.
layout_with_pmds(g, pivots, weights = NA, D = NULL, dim = 2) layout_igraph_pmds(g, pivots, weights = NA, D = NULL, circular)
layout_with_pmds(g, pivots, weights = NA, D = NULL, dim = 2) layout_igraph_pmds(g, pivots, weights = NA, D = NULL, circular)
g |
igraph object |
pivots |
number of pivots |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
D |
precomputed distances from pivots to all nodes (if available, default: NULL) |
dim |
dimensionality of layout (defaults to 2) |
circular |
not used |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight)
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
matrix of coordinates
David Schoch
Brandes, U. and Pich, C. (2006). Eigensolver Methods for Progressive Multidimensional Scaling of Large Data. In International Symposium on Graph Drawing (pp. 42-53). Springer
## Not run: library(igraph) library(ggraph) g <- sample_gnp(1000, 0.01) xy <- layout_with_pmds(g, pivots = 100) ## End(Not run)
## Not run: library(igraph) library(ggraph) g <- sample_gnp(1000, 0.01) xy <- layout_with_pmds(g, pivots = 100) ## End(Not run)
stress majorization for larger graphs based on a set of pivot nodes.
layout_with_sparse_stress(g, pivots, weights = NA, iter = 500) layout_igraph_sparse_stress(g, pivots, weights = NA, iter = 500, circular)
layout_with_sparse_stress(g, pivots, weights = NA, iter = 500) layout_igraph_sparse_stress(g, pivots, weights = NA, iter = 500, circular)
g |
igraph object |
pivots |
number of pivots |
weights |
ignored |
iter |
number of iterations during stress optimization |
circular |
not used |
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
matrix of xy coordinates
David Schoch
Ortmann, M. and Klimenta, M. and Brandes, U. (2016). A Sparse Stress Model. https://arxiv.org/pdf/1608.08909.pdf
## Not run: library(igraph) library(ggraph) g <- sample_gnp(1000, 0.005) ggraph(g, layout = "sparse_stress", pivots = 100) + geom_edge_link0(edge_colour = "grey66") + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() ## End(Not run)
## Not run: library(igraph) library(ggraph) g <- sample_gnp(1000, 0.005) ggraph(g, layout = "sparse_stress", pivots = 100) + geom_edge_link0(edge_colour = "grey66") + geom_node_point(shape = 21, fill = "grey25", size = 5) + theme_graph() ## End(Not run)
Using a set of eigenvectors of matrices associated with a graph as coordinates
layout_with_eigen(g, type = "laplacian", ev = "smallest") layout_igraph_eigen(g, type = "laplacian", ev = "smallest", circular)
layout_with_eigen(g, type = "laplacian", ev = "smallest") layout_igraph_eigen(g, type = "laplacian", ev = "smallest", circular)
g |
igraph object |
type |
matrix to be used for spectral decomposition. either 'adjacency' or 'laplacian' |
ev |
eigenvectors to be used. Either 'smallest' or 'largest'. |
circular |
not used |
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
matrix of xy coordinates
David Schoch
library(igraph) g <- sample_gnp(50, 0.2) xy <- layout_with_eigen(g, type = "adjacency", ev = "largest") xy <- layout_with_eigen(g, type = "adjacency", ev = "smallest") xy <- layout_with_eigen(g, type = "laplacian", ev = "largest") xy <- layout_with_eigen(g, type = "laplacian", ev = "smallest")
library(igraph) g <- sample_gnp(50, 0.2) xy <- layout_with_eigen(g, type = "adjacency", ev = "largest") xy <- layout_with_eigen(g, type = "adjacency", ev = "smallest") xy <- layout_with_eigen(g, type = "laplacian", ev = "largest") xy <- layout_with_eigen(g, type = "laplacian", ev = "smallest")
force-directed graph layout based on stress majorization. Similar to Kamada-Kawai, but generally faster and with better results.
layout_with_stress( g, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 ) layout_igraph_stress( g, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30, circular )
layout_with_stress( g, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 ) layout_igraph_stress( g, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30, circular )
g |
igraph object |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
mds |
should an MDS layout be used as initial layout (default: TRUE) |
bbox |
width of layout. Only relevant to determine the placement of disconnected graphs |
circular |
not used |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. 'ggraph' natively supports the layout.
matrix of xy coordinates
Gansner, E. R., Koren, Y., & North, S. (2004). Graph drawing by stress majorization. In International Symposium on Graph Drawing (pp. 239-250). Springer, Berlin, Heidelberg.
library(igraph) set.seed(665) g <- sample_pa(100, 1, 1, directed = FALSE) # calculate layout manually xy <- layout_with_stress(g) # use it with ggraph ## Not run: library(ggraph) ggraph(g, layout = "stress") + geom_edge_link0(edge_width = 0.2, colour = "grey") + geom_node_point(col = "black", size = 0.3) + theme_graph() ## End(Not run)
library(igraph) set.seed(665) g <- sample_pa(100, 1, 1, directed = FALSE) # calculate layout manually xy <- layout_with_stress(g) # use it with ggraph ## Not run: library(ggraph) ggraph(g, layout = "stress") + geom_edge_link0(edge_width = 0.2, colour = "grey") + geom_node_point(col = "black", size = 0.3) + theme_graph() ## End(Not run)
force-directed graph layout based on stress majorization in 3D.
layout_with_stress3D( g, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 )
layout_with_stress3D( g, weights = NA, iter = 500, tol = 1e-04, mds = TRUE, bbox = 30 )
g |
igraph object |
weights |
possibly a numeric vector with edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). By default, weights are ignored. See details for more. |
iter |
number of iterations during stress optimization |
tol |
stopping criterion for stress optimization |
mds |
should an MDS layout be used as initial layout (default: TRUE) |
bbox |
width of layout. Only relevant to determine the placement of disconnected graphs |
Be careful when using weights. In most cases, the inverse of the edge weights should be used to ensure that the endpoints of an edges with higher weights are closer together (weights=1/E(g)$weight).
matrix of xyz coordinates
Gansner, E. R., Koren, Y., & North, S. (2004). Graph drawing by stress majorization. In International Symposium on Graph Drawing (pp. 239-250). Springer, Berlin, Heidelberg.
Using the UMAP dimensionality reduction algorithm as a graph layout
layout_with_umap(g, pivots = NULL, ...) layout_igraph_umap(g, circular, ...)
layout_with_umap(g, pivots = NULL, ...) layout_igraph_umap(g, circular, ...)
g |
igraph object |
pivots |
if not NULL, number of pivot nodes to use for distance calculation (for large graphs). |
... |
additional parameters for umap. See the |
circular |
not used |
The layout_igraph_* function should not be used directly. It is only used as an argument for plotting with 'igraph'. UMAP can be tuned by many different parameters. Refer to the documentation at https://github.com/jlmelville/uwot for help
matrix of xy coordinates
David Schoch
McInnes, Leland, John Healy, and James Melville. "Umap: Uniform manifold approximation and projection for dimension reduction." arXiv preprint arXiv:1802.03426 (2018).
library(igraph) g <- sample_islands(10, 20, 0.6, 10) # xy <- layout_with_umap(g, min_dist = 0.5)
library(igraph) g <- sample_islands(10, 20, 0.6, 10) # xy <- layout_with_umap(g, min_dist = 0.5)
A dataset containing the subway network of Berlin
metro_berlin
metro_berlin
igraph object
Kujala, Rainer, et al. "A collection of public transport network data sets for 25 cities." Scientific data 5 (2018): 180089.
Multilevel network, where both levels have different structural features
multilvl_ex
multilvl_ex
igraph object