我有由互动对组成的数据,我想将其表示为网络。虽然大多数交互是单向的,但有些是双向的,我希望能够代表这一点。
我可以按颜色执行此操作,但是对于单向交互而言,方向很重要,因此我认为我可以使用箭头,但是我不知道如何从双向边缘移除箭头(或在另一端添加箭头)。我正在使用tidygraph
和ggraph
软件包,由于我不知道该如何传递给geom_edge_link
中的美学调用,因此正在努力实现它。我还尝试了对tbl_graph
对象进行子设置,并将其作为数据来分隔geom_edge_link
层,但这没有用。
这是我到目前为止的MWE:
nodes <- structure(list(node = structure(c(1L, 2L, 5L, 6L, 8L, 7L, 4L,
3L), .Label = c("A", "B", "D", "E", "F", "Q", "S", "T"), class = "factor")), .Names = "node", row.names = c(NA,
-8L), class = "data.frame")
df <- structure(list(from = c("A", "B", "F", "Q", "T", "S", "A", "T",
"F"), to = c("E", "D", "Q", "S", "F", "T", "D", "A", "E"), status = c("Bi",
"Bi", "Uni", "Uni", "Uni", "Uni", "Uni", "Uni", "Uni"), weight = c(2,
2, 1, 1, 1, 1, 1, 1, 1)), .Names = c("from", "to", "status",
"weight"), row.names = c(NA, -9L), class = c("tbl_df", "tbl",
"data.frame"))
library(tidygraph)
library(ggraph)
tbl_graph(nodes = nodes, edges = df, directed = T) %>%
ggraph(layout = 'linear', circular = TRUE) +
geom_edge_link(aes(colour = status),
arrow = arrow(length = unit(4, 'mm')),
start_cap = circle(3, 'mm'),
end_cap = circle(3, 'mm')) +
geom_node_point(size = 5) +
coord_fixed() +
geom_node_text(aes(label = node), repel = T) +
scale_edge_width(range = c(0.5, 1)) +
theme_graph()