dev/R_ggraph/layout_manual.R

#' Manually specify a layout for layout_tbl_graph
#'
#' This layout function lets you pass the node positions in manually. The
#' supplied positions must match the order of the nodes in the tbl_graph
#'
#' @param graph An `tbl_graph` object
#'
#' @param x,y Expressions with the x and y positions of the nodes
#'
#' @param circular Ignored
#'
#' @return A data.frame with the columns `x`, `y`, `circular` as
#' well as any information stored as node variables in the tbl_graph.
#'
#' @family layout_tbl_graph_*
#'
#' @importFrom rlang enquo eval_tidy
#'
layout_tbl_graph_manual <- function(graph, x, y, circular) {
    if (circular) {
        warning('circular argument ignored for manual layout')
    }
    x <- enquo(x)
    y <- enquo(y)
    layout <- data.frame(
        x = eval_tidy(x, .N()),
        y = eval_tidy(y, .N())
    )
    extraData <- as_tibble(graph, active = 'nodes')
    layout <- cbind(layout, extraData[, !names(extraData) %in% names(layout), drop = FALSE])
    layout$circular <- FALSE
    layout
}
kbodwin/longnet documentation built on Nov. 4, 2019, 3:33 p.m.