data("Tiger")
g <- transition_graph(Tiger)
g
library(igraph)
plot(g)
# plot with a fixed layout and curved edges
plot(g,
layout = rbind(c(-1, 0), c(1, 0)), rescale = FALSE,
edge.curved = curve_multiple_directed(g, .8),
edge.loop.angle = -pi / 4,
vertex.size = 60
)
## Use visNetwork (if installed)
if(require(visNetwork)) {
g_vn <- toVisNetworkData(g)
nodes <- g_vn$nodes
edges <- g_vn$edges
# add manual layout
nodes$x <- c(-1, 1) * 200
nodes$y <- 0
visNetwork(nodes, edges) %>%
visNodes(physics = FALSE) %>%
visEdges(smooth = list(type = "curvedCW", roundness = .6), arrows = "to")
}
## Plot an individual graph for each actions
for (a in Tiger$actions) {
g <- transition_graph(Tiger, action = a)
plot(g,
layout = rbind(c(-1, 0), c(1, 0)), rescale = FALSE,
edge.curved = curve_multiple_directed(g, .8),
edge.loop.angle = cumsum(which_loop(g)) * (-pi / 8),
vertex.size = 60
)
}
Run the code above in your browser using DataLab