mod <- stages_bhc(full(Titanic))
get_edges(mod)
get_vertices(mod)
if (FALSE) {
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()
}
Run the code above in your browser using DataLab