Example:
require(igraph)
require(tidygraph)
require(ggraph)
require(data.table)
nodes <- data.table(id = 1:6,
label = c("a1", "b1", "a2", "a3", "b2", "a4"),
type = c("A", "B", "A", "A", "B", "A"))
edges <- data.table(from = c(1, 2, 2, 3, 5),
to = c(2, 3, 4, 5, 6))
network <- graph_from_data_frame(d = edges, vertices = nodes, directed = TRUE)
ggraph(network) +
geom_edge_link(arrow = arrow(length = unit(4, 'mm')),
start_cap = circle(3, 'mm'),
end_cap = circle(3, 'mm')) +
geom_node_point(aes(color = type), size = 7) +
geom_node_text(aes(label = label)) +
theme_graph()
This is what we get:
Then we create projections:
V(network)$type <- bipartite_mapping(network)$type
network_projections <- bipartite_projection(network)
ggraph(network_projections$proj1) +
geom_edge_link(arrow = arrow(length = unit(4, 'mm')),
start_cap = circle(3, 'mm'),
end_cap = circle(3, 'mm')) +
geom_node_point(size = 7, color = 2, alpha = .6) +
geom_node_text(aes(label = label)) +
theme_graph()
And this is what we get:
Projection shows link a2 -> a3, which should not be there. Which clearly means that directionality was not taken into the account.
As much as I found out - underlying incidence matrix computed by igraph library is computed in a way that does not consider directionality. Is there some function that I missed or other R libraries out there that allow for directional projections of bipartite networks?


