igraph-conversion {stagedtrees}R Documentation

igraph conversion

Description

Obtain the graph representation of a staged tree or a CEG as an object from the igraph package.

Usage

get_edges(x, ignore = x$name_unobserved, ...)

## S3 method for class 'sevt'
get_edges(x, ignore = x$name_unobserved, ...)

get_vertices(x, ignore = x$name_unobserved, ...)

## S3 method for class 'sevt'
get_vertices(x, ignore = x$name_unobserved, ...)

## S3 method for class 'ceg'
get_edges(x, ignore = x$name_unobserved, ...)

## S3 method for class 'ceg'
get_vertices(x, ignore = x$name_unobserved, ...)

as_igraph(x, ignore = x$name_unobserved, ...)

## S3 method for class 'sevt'
as_igraph(x, ignore = x$name_unobserved, ...)

## S3 method for class 'ceg'
as_igraph(x, ignore = x$name_unobserved, ...)

Arguments

x

an object of class sevt or ceg.

ignore

vector of stages which will be ignored and excluded, by default the name of the unobserved stages stored in x$name_unobserved.

...

additional parameters.

Details

Functions to transalte the graph structure of a sevt or ceg object to a graph object from the igraph package. Additional functions that extract the edge lists and the vertices are available. This can be useful, for example to plot the staged tree with igraph or additional packages (see the examples).

Value

for get_edges: the edges list corresponding to the graph associated to x.

for get_vertices: the vertices list corresponding to the graph associated to x.

for as.igraph: a graph object from the igraph package.

Examples

mod <- stages_bhc(full(Titanic))
get_edges(mod)
get_vertices(mod)
## Not run: 
library(igraph)
library(ggraph)
######## sevt example ########
## convert to igraph object
g <- as_igraph(mod)
## plot with igraph directly
plot(g, layout = layout_with_sugiyama)
## plot with ggraph
ggraph(g, "sugiyama") +
  geom_edge_fan(
    aes(
      label = label,
      label_pos = 0.5 + runif(length(label), -0.1, 0.1)
    ),
    angle_calc = "along", show.legend = FALSE, check_overlap = FALSE,
    end_cap = circle(0.02, "npc"),
    arrow = grid::arrow(
      angle = 25,
      length = unit(0.025, "npc"),
      type = "closed"
    )
  ) +
  geom_node_point(aes(x = x, y = y, color = stage),
    size = 5,
    show.legend = FALSE
  ) +
  ggforce::theme_no_axes() + coord_flip() + scale_y_reverse()

######## ceg example ########
g.ceg <- as_igraph(ceg(mod))
### igraph plotting functions can be used
plot(g.ceg, layout = layout.sugiyama)
### igraph object can be also plotted with ggplot2 and ggraph
ggraph(g.ceg, "sugiyama") +
  geom_edge_fan(
    aes(
      label = label,
      color = label,
      label_pos = 0.5 + runif(length(label), -0.1, 0.1)
    ),
    angle_calc = "along", show.legend = FALSE, check_overlap = FALSE,
    end_cap = circle(0.02, "npc"),
    arrow = grid::arrow(
      angle = 25,
      length = unit(0.025, "npc"),
      type = "closed"
    )
  ) +
  geom_node_point(aes(x = x, y = y, color = stage), size = 3, show.legend = FALSE) +
  ggforce::theme_no_axes() + coord_flip() + scale_y_reverse()

## End(Not run)

[Package stagedtrees version 2.3.0 Index]