Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export(aging.ba.game)
export(aging.barabasi.game)
export(aging.prefatt.game)
export(algorithm)
export(align_layout)
export(all_shortest_paths)
export(all_simple_paths)
export(alpha.centrality)
Expand Down
38 changes: 33 additions & 5 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -877,12 +877,18 @@ layout.circle <- function(..., params = list()) {
#'
#' `layout_nicely()` tries to choose an appropriate layout function for the
#' supplied graph, and uses that to generate the layout. The current
#' implementation works like this: \enumerate{ \item If the graph has a graph
#' attribute called \sQuote{layout}, then this is used. If this attribute is an
#' R function, then it is called, with the graph and any other extra arguments.
#' implementation works like this:
#' \enumerate{
#' \item If the graph has a graph attribute called \sQuote{layout},
#' then this is used. If this attribute is an R function, then it is called, with the graph and any other extra arguments.
#'
#' \item Otherwise, if the graph has vertex attributes called \sQuote{x} and
#' \sQuote{y}, then these are used as coordinates. If the graph has an
#' additional \sQuote{z} vertex attribute, that is also used. \item Otherwise,
#' additional \sQuote{z} vertex attribute, that is also used.
#'
#' \item Otherwise, if the graph is a forest and has less than 30 vertices, `layout_as_tree()` is used.
#'
#' \item Otherwise,
#' if the graph is connected and has less than 1000 vertices, the
#' Fruchterman-Reingold layout is used, by calling `layout_with_fr()`.
#' \item Otherwise the DrL layout is used, `layout_with_drl()` is called. }
Expand Down Expand Up @@ -916,6 +922,7 @@ layout_nicely <- function(graph, dim = 2, ...) {
## 1. If there is a 'layout' graph attribute, we just use that.
## 2. Otherwise, if there are vertex attributes called 'x' and 'y',
## we use those (and the 'z' vertex attribute as well, if present).
## 3. If the graph is a forest and has less than 30 vertices, layout_as_tree is used
## 3. Otherwise, if the graph is small (<1000) we use
## the Fruchterman-Reingold layout.
## 4. Otherwise we use the DrL layout generator.
Expand Down Expand Up @@ -954,10 +961,15 @@ layout_nicely <- function(graph, dim = 2, ...) {
}

args$graph <- graph

if (is_forest(graph) && vcount(graph) <= 30) {
return(do.call(layout_as_tree, args))
}

args$dim <- dim

if (vcount(graph) < 1000) {
do.call(layout_with_fr, args)
align_layout(graph, do.call(layout_with_fr, args))
Comment thread
schochastics marked this conversation as resolved.
} else {
do.call(layout_with_drl, args)
}
Expand Down Expand Up @@ -3008,3 +3020,19 @@ drl_defaults <- list(
final = igraph.drl.final,
refine = igraph.drl.refine
)

#' Align a vertex layout
#' This function centers a vertex layout on the coordinate system origin and
#' rotates the layout to achieve a visually pleasing alignment with the coordinate
#' axes. Doing this is particularly useful with force-directed layouts such as [layout_with_fr()].
#' @param graph The graph whose layout is to be aligned.
#' @param layout A matrix whose rows are the coordinates of vertices.
#' @return modified layout matrix
#' @export
#' @examples
#' g <- make_lattice(c(3, 3))
#' l1 <- layout_with_fr(g)
#' l2 <- align_layout(g,l1)
#' plot(g, layout = l1)
#' plot(g, layout = l2)
align_layout <- layout_align_impl
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ reference:
- has_concept("plot.common")
- has_concept("plot.shapes")
- vertex.shape.pie
- align_layout
- subtitle: Graph coloring
- contents:
- has_concept("coloring")
Expand Down
32 changes: 32 additions & 0 deletions man/align_layout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions man/layout_nicely.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading