R: Create a ggraph plot

ggraph {ggraph} | R Documentation

## Create a ggraph plot

### Description

This function is the equivalent of `ggplot` in ggplot2. It takes care of setting up the plot object along with creating the layout for the plot based on the graph and the specification passed in. Alternatively a layout can be prepared in advance using `create_layout` and passed as the data argument. See Details for a desciption of all available layouts.

### Usage

    ggraph(graph, layout = "auto", ...)

    create_layout(graph, layout, circular, ...)

    ## Default S3 method:
    create_layout(graph, layout, ...)

    ## S3 method for class 'dendrogram'
    create_layout(graph, layout, circular = FALSE, ...)

    ## S3 method for class 'igraph'
    create_layout(graph, layout, circular = FALSE, ...)

    ## S3 method for class 'hclust'
    create_layout(graph, layout, circular = FALSE, ...)

    ## S3 method for class 'network'
    create_layout(graph, layout, circular = FALSE, ...)

### Arguments

`graph` | The object containing the graph. See Details for a list of supported classes. Or a `layout_ggraph` object as returned from `create_layout` in which case all subsequent arguments is ignored.
`layout` | The type of layout to create.
`...` | Arguments passed on to the layout function.
`circular` | Should the layout be transformed into a radial representation. Only possible for some layouts. Defaults to `FALSE`

### Details

Following is a short description of the different layout types available in ggraph. Each layout is further described in its own help pages.

Dendrogram objects

The `dendrogram` class is used to store binary tree from e.g. hierarchical clustering. The layouts provided for this class is constrained to tree-like representations. `hclust` objects are supported through automatic conversion to dendrogram objects and thus supports the same layouts.

`auto`

  The default layout. Eqivalent to `layout = 'dendrogram'`

`dendrogram`

  Creates a tree using the heights already defined in the dendrogram object. See `layout_dendrogram_dendrogram` for further details

`even`

  Ignores the heights given by the dendrogram object and instead spreads the branch points out with an even distance. See `layout_dendrogram_even` for further details

Further, if the layouts provided for igraph objects are needed for dendrogram objects `den_to_igraph` is provided to convert dendrograms to igraph.

igraph objects

Any type of regular graph/network data can be represented as an igraph object. Because of this the different layouts that can be applied to igraph objects are quite diverse, but not all layouts makes sense to all types of graphs. It is up to the user to understand their data and choose an appropriate layout. For standard node-edge diagrams igraph itself defines a long range of different layout functions that are all available through the `igraph` layout where the specific layout is specified using the `algorithm` argument. In order to minimize typing all igraph algorithms can also be passed directly into the `layout` argument. `network` objects are supported by automatic conversion to igraph objects using `network_to_igraph` and thus supports the same layouts.

`auto`

  The default layout. Equivalent to `layout = 'igraph', algorithm = 'nicely'`

`igraph`

  Use one of the internal igraph layout algorithms. The algorithm is specified using the `algorithm` argument. All strings accepted by the `algorithm` argument can also be supplied directly into `layout`. See `layout_igraph_igraph` for further details

`dendrogram`

  Lays out the nodes in a tree-like graph as a dendrogram with leaves set at 0 and parents 1 unit above its tallest child. See `layout_igraph_dendrogram` for further details

`manual`

  Lets the user manually specify the location of each node by supplying a data.frame with an `x` and `y` column. See `layout_igraph_manual` for further details

`linear`

  Arranges the nodes linearly or circularly in order to make an arc diagram. See `layout_igraph_linear` for further details

`treemap`

  Creates a treemap from the graph, that is, a space-filing subdivision of rectangles showing a weighted hierarchy. See `layout_igraph_treemap` for further details

`circlepack`

  Creates a layout showing a hierarchy as circles within circles. Conceptually equal to treemaps. See `layout_igraph_circlepack` for further details

`partition`

  Create icicle or sunburst charts, where each layer subdivides the division given by the preceeding layer. See `layout_igraph_partition` for further details

`hive`

  Positions nodes on axes spreading out from the center based on node attributes. See `layout_igraph_hive` for further details

### Value

For `ggraph()` an object of class gg onto which layers, scales, etc. can be added. For `create_layout()` an object inherting from `layout_ggraph`. `layout_ggraph` itself inherits from `data.frame` and can be considered as such. The data.frame contains the node positions in the `x` and `y` column along with additional columns generated by the specific layout, as well as node parameters inherited from the graph. Additional information is stored as attributes to the data.frame. The original graph object is stored in the `graph` attribute and the `circular` attribute contains a logical indicating whether the layout has been transformed to a circular representation.

### See Also

`get_edges` for extracting edge information from the layout and `get_con` for extracting path information.

### Examples

    require(igraph)
    gr <- make_graph('bull')
    layout <- create_layout(gr, layout = 'igraph', algorithm = 'kk')

[Package ggraph version 1.0.2 Index]