igraph-conversion | R Documentation |
Obtain the graph representation of a staged tree or a CEG as an object from the igraph package.
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, ...)
x |
an object of class |
ignore |
vector of stages which will be ignored and excluded,
by default the name of the unobserved stages stored in
|
... |
additional parameters. |
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).
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.